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
RE: What would be the output of the following program...
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 * '