electric
2012-08-30 08:02:03 UTC
#include
int main()
{
char name[20]="Seattle",(*ctr)[]=name; //Shows warning
*ptr=name; //works fine as expected
printf("%s,%s",ptr,ctr);
}
OUTPUT: Seattle,Seattle
1)Why does "(*ctr)[]=name" show following warning? "warning: initialization from incompatible pointer type|" but there is no warning when I write "(*ctr)[]=&name". Don't we write the string/array name on the right side of "=" operator when assigning base address of strings/array?Why is "*ctr)[]=&name" working fine even though we are using "&" before an array name?Isn't "&" operator used only before single variables, not arrays?
2)As string is an array of characters, why dont' we declare the string pointer as "char (*ctr)[]" nstead of "char *ctr"?Going by the answer of a top contributor in the following question
http://answers.yahoo.com/question/index;_ylt=Amz6Je7QyeK5fyTuVqE3bgfty6IX;_ylv=3?qid=20120731063310AAZtM5j
the correct declaration for a pointer to an array of characters (eg string) should be "char (*ctr)[];" where "ctr" is the pointer.Does it mean a "pointer to an array of characters(string)" is the same as "a pointer to a character"?God, I am really confused about it.