Belows are simple code to find what the pointer to array is.
#include <stdio.h>
typedef unsigned short int Ushort;
void InputYear(char (*name), Ushort *year);
int main(int argc, const char * argv[]) {
Ushort year;
char name[11] ;
InputYear(name, &year);
printf("MY name is %s", message);
printf("%d", year);
}
void InputYear(char (*name), Ushort *year){
printf("please enter your name and year");
scanf("%s %hd" ,name, year);
}
But question is, why it doesn't work if i change char name[11]
--> char *name
?
The error is "segmentation fault : 11".
I learned that the name of array is also a pointer that indicates the address of first array value. In this respect, I think that char name[11]
and char *name
are same.
Or is there anything that I didn't know about it?
and Extra Question :
int a = 1;
int* b = &a;
printf("%s", *b);
it works. The point is that second argument of printf is the value itself, not address. but,
char hi[11] = "message";
printf("%s", hi);
in this case, second argument of printf is address itself, not value like above. What is it?? why does it happen?
Thanks you so much!