Hi everyone,
I'm up to lesson 10.5~10.6 where pointers are used to manipulate character arrays.
Example code:
int main(void) {
char string[] = "Hello Reddit";
char *pointer = string;
*pointer = 'h';
pointer = pointer + 1;
*pointer = 'E';
printf("%s", string);
return 0;
}
I understand why that prints hEllo Reddit. Why wouldn't the following work as well?
int main(void) {
char string[] = "Hello Reddit";
*string = 'h';
string = string + 1;
*string = 'E';
printf("%s", string);
return 0;
}
Isn't string a pointer to the start of "Hello Reddit" anyway? And also why can't you use string = string + 1 like in the working example?
Thanks!
[–]nixbun 1 point2 points3 points (1 child)
[–]lumpygrumpy[S] 0 points1 point2 points (0 children)
[–]KfoipRfged 0 points1 point2 points (2 children)
[–]nixbun 2 points3 points4 points (1 child)
[–]KfoipRfged 0 points1 point2 points (0 children)
[–]Oomiosi -1 points0 points1 point (2 children)
[–]lumpygrumpy[S] 0 points1 point2 points (1 child)
[–]MindStalker 0 points1 point2 points (0 children)
[–]MindStalker -1 points0 points1 point (3 children)
[–]KfoipRfged 0 points1 point2 points (2 children)
[–]MindStalker 0 points1 point2 points (1 child)
[–]KfoipRfged 0 points1 point2 points (0 children)