c - why does it make sense that indexing a character pointer is an int?
Posted
by hatorade
on Stack Overflow
See other posts from Stack Overflow
or by hatorade
Published on 2010-04-18T10:13:36Z
Indexed on
2010/04/18
10:23 UTC
Read the original article
Hit count: 178
char *a = "apple";
printf("%s\n", a); \\ fine
printf("%s\n", a[1]); \\ compiler complains an int is being passed
Why does indexing a string pointer give me an int? I was expecting it to just print the string starting at position one (which is actually what happens when i use &a[1]
instead). why do i need to get the address?
© Stack Overflow or respective owner