What would be the output of the following program? main() { const int x=5; int *ptrx; ptrx=&x; *ptrx=10; printf("%d",x); } a) 5 b) 10 c) Error d) Garbage value

This question is related to Sonata Interview

Showing Answers 1 - 6 of 6 Answers

Rage

  • Dec 5th, 2005
 

The Answer is C. ERROR!First of all you cant store the address(&x) of a const int in a normal integer pointer(*ptrx)we need to declare the pointer(ptrx) as "const int *ptrx ; ". Well even after this you cant change the value of *ptrx since its a const pointer. Therefore it results in a ERRORThe error before modification wud be "cannot conver ' const int * ' to ' int * ' "

  Was this answer useful?  Yes

Krupa

  • May 25th, 2006
 

option b is the answer

  Was this answer useful?  Yes

manoj

  • Nov 11th, 2006
 

the answer is 10 .please dont put wrong answers and guess so that others may not be misguided.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions