I know that for a given integer array, a pointer to that integer array, I can access the integer array using something like this:
int main(){
int x[4] = {0,1,2,3};
int *ptr;
ptr = x;
for(int i = 0; i < 4; i++){
printf("%d", *(ptr+i));
}
return 0;
}
Now say I have a character array instead, doing the same thing doesnt work.
int main(){
char x[4] = "Haha";
char *ptr;
ptr = x;
for(int i = 0; i < 4; i++){
printf("%s", *(ptr+i));
}
return 0;
}
Apparently *(ptr+i) in the first code increments the pointer to the integer 4 bytes each time. It doesnt work for the second code. How do I use the same notation for character array? I think the idea is to increment one char each time.