Pointer explanation

I'm testing pointers and I have this litle code:

char test = "A";

void setup() {

Serial.begin(9600);

}

void loop() 
{
 serialEvent(&test);
}


void serialEvent(char *Value) 
{
Serial.println(*Value);
}

This give an error SerialEvent.cpp:5: erro: invalid conversion from ‘const char*’ to ‘char’

If using this it's ok

int test = 1;

void setup() {

Serial.begin(9600);

}

void loop() 
{
 serialEvent(&test);
}


void serialEvent(int *Value) 
{
Serial.println(*Value);
}

Why diferent data types is not working?
In serialEvent function is expecting a pointer and I'm passing is address to point on serialEvent(&test) is this the right way of using pointers?

In your first example, test is already a pointer, so referencing it's address isn't doing what you think it's doing. Any array declaration (strings are just null terminated char arrays) returns a pointer to first element in that array. So when you pass &value in the first example, you are telling it to pass the address of the pointer to your array to the function.

As an example, consider the following declaration:

char myString[] = "Hello";
char * myStringPointer;

int myInt = 25;
int * myIntPointer;

To set the pointers equal to the appropriate values, you would do the following:

myStringPointer = myString;
myIntPointer = &myInt;

Notice that because myString is already a pointer, you don't need the & symbol to reference it.

So if I use arrays(or Strings which are char arrays) I can use the array name to refer it self as a point right?

HugoPT:
So if I use arrays(or Strings which are char arrays) I can use the array name to refer it self as a point right?

Yes, you don't need to reference when passing it as an argument.

char test = "A";

This is not probably what you think. If you want that variable test holds a single character, use single quotes like this:

char test = 'A';

Or if you meant to declare a character array, add [] after the variable name:

char test[] = "A";
char test = "A";

I would be surprised it the code above doesn't raise a compiler error or warning.

pekkaa:

char test = "A";

I would be surprised it the code above doesn't raise a compiler error or warning.

Good catch, I completely skipped over that part of it.

Every day pass more I love this forum.Your answer is right it is now working fine.This is a big step to me to try myself learn more about pointers.I believe they are very powerful so I'm decided to learn all about them.Sometimes its not easy to filter the information on the web about them.
Anyway I will close this lesson in my brain and move to the next test sketch using pointers.
Thanks for all answers It really help me