c - Pointer to memory -
i'm learning c , have problems whit pointers. i'm triying print memory slot every declared variable, when declare pointer char[], not work.
here's code:
int main () { char a[3]; // variable problem int b; float c; char d; int e=4; char *pachar; //a char type variable pointer. int *paint; float *pafloat; char *pacharr; int *paintt; pachar = &a; // when try assign memory pointer, shows warning message. paint = &b; pafloat = &c; pacharr = &d; paintt = &e; printf("%p \n",pachar); printf("%p \n",paint); printf("%p \n",pafloat); printf("%p \n",pacharr); printf("%p \n",paintt); return(0); }
this warning message. doing wrong?
"warning: assignment incompatible pointer type"
you declared a
array of char
:
char a[3];
name a
represents array, can interpreted pointer initial element of array. therefore not need &
when assign a
pointer:
pachar = a;
when take address of a
in &a
expression, pointer array of 3 characters. trying assign pointer-to-an-array pointer-to-char triggers compiler warning.
Comments
Post a Comment