In the following code int mainvoid int a5 int b3 char s Thi
In the following code, int main(void) {int a=5; int b=3; char s[] = \"This Is A Test\"; int *p - char *cp; p = &a; cp = s; (*P)++; cp+=6 p ++/* line (**): print statements will be after this line */} and memory is laid out like this table. What is the output if after line (**) you print one of these? (You can use the third column of the first table to show and trace the value of each variable.)
Solution
printf(\"%d\",a) = 6.
(*p++) would increment the value hold by a from 5 to 6. so a will have 6.
printf(\"%x\",&a) = 0x1000, the address of a in memory
printf(\"%p\",p) = 0x1004 (address of b)
first in p the values is 0x1000 (address of a), p++ operator increses the address by size of pointer( i.e. 4) so, the 0x1000 becomes 0x1004.
printf(\"%d\",*p) = 3.
the values in 0x1004 is 3 hence the output.
printf(\"%x\",&p) = 0x1008, the address where p is stored.
printf(\"%c\",*cp) = \'s\' .
cp = s, would assign the first address of s to cp. &s[0] will be assigned to cp.
*cp is the value at the address &s[0] which is \'s\'. hence the ouptut.
![In the following code, int main(void) {int a=5; int b=3; char s[] = \ In the following code, int main(void) {int a=5; int b=3; char s[] = \](/WebImages/17/in-the-following-code-int-mainvoid-int-a5-int-b3-char-s-thi-1029987-1761533722-0.webp)