Const - Find Output of Program :: Discussion


4.What will be the output of the program?
A.5
B.10
C.Garbage Value
D.Error
Answer:  Option  D
Explanation:

Step 1const int x=5; The constant variable x is declared as an integer data type and initialized with value '5'.

Step 2const int *ptrx; The constant variable ptrx is declared as an integer pointer.

Step 3ptrx = &x; The address of the constant variable x is assigned to integer pointer variable ptrx.

Step 4*ptrx = 10; Here we are indirectly trying to change the value of the constant vaiable x. This will result in an error.

To change the value of const variable x we have to use *(int *)&x = 10;

Tutorial Link:
Published by:Michael Daani

Comments are not available

Post your comments here:

Optional

Date to Date Current Affairs 2022

PakMCQs.net

Quick Links

GAT Subject



   Computer Science    English Mcqs    Agriculture    

Engineering



   Computer Science    Civil Engineering    

Technical



   Networking    Electronics    Database    

Past Papers



   Model Papers    FPSC Papers