0
Can anyone please tell me how the value of *++ptr becomes 17?
2 ответов
+ 2
May I ask first, what did you think happened in line 6 and 9? what are you incrementing? is it value at address of <var> or some other address in memory?
Different compiler yields different result.
+ 1
Keerthana.S the value 17 is whatever happens to be in memory two bytes above the storage for main's local variables. You can see this in a more controlled manner if you define two more local char variables above var.
char c = 2;
char b = 1;
char var=20;
char *ptr=&var;
*++ptr=2;
Now ptr will point to c, and it will no longer print 17. It will print whatever value you use to initialize c (in this example: 2).