problem with string

i am not able to catch the difference between the following two piece of code
1
2
char name[20]="john";
printf("%s",name);


and

1
2
char name[20]="john";
printf("%s",&name);

why do both give me the same output?If both are same why does the following statement give me garbage value

printf("%s",&name+2);

whereas

printf("%s",name+2);
gives me the expected output...
plz help me in getting a crystal clear picture of this
well...it is a matter of pointers. When using the & operator, you are actually saying "the address of ..."

you can read about it here:
http://www.cplusplus.com/doc/tutorial/pointers/
Last edited on
Topic archived. No new replies allowed.