in Programming retagged by
420 views
1 vote
1 vote

Output of following program? 

#include<stdio.h>
int main() 
{ 
int *ptr; 
int x; 
ptr=&x; 
*ptr=0; 
printf("x=%d\n",x); 
printf("*ptr=%d\n",*ptr); 
*ptr+=5; 
printf("x=%d\n",x); 
printf("*ptr=%d\n",*ptr); 
(*ptr)++; 
printf(“x=%d\n",x); 
printf("*ptr=%d\n",*ptr); 
return 0; 
} 
  1. $x=0$ 
    $^*ptr=0$
    $x=5$ 
    $^*ptr=5$ 
    $x=6$ 
    $^*ptr=6$
  2. $x=$garbage value 
    $^*ptr=0$ 
    $x=$garbage value 
    $^*ptr=5$ 
    $x=$garbage value 
    $^*ptr=6$
  3. $x=0$ 
    $^*ptr=0$ 
    $x=5$ 
    $^*ptr=5$ 
    $x=$garbage value 
    $^*ptr=$garbage value
  4. $x=0$ 
    $^*ptr=0$ 
    $x=0$ 
    $^*ptr=0$ 
    $x=0$ 
    $^*ptr=0$
in Programming retagged by
420 views

1 Answer

1 vote
1 vote
A should be correct answer

 

 x=0
∗ptr=0
 x=5
∗ptr=5
 x=6
∗ptr=6

2 Comments

after (*ptr)++ . why the value of x will not be 5 and then the last *ptr will be 6. as ++ need to be used once then incremented??
0
0
(*ptr)++ is equivalent to *ptr += 5;

Hence the value of *ptr will increment than there,
0
0
Answer:

Related questions