C Preprocessor - Find Output of Program :: Discussion


9.What will be the output of the program?
A.3
B.4
C.0
D.No output
Answer:  Option  A
Explanation:

The macro MIN(x, y) (x<y)? x : y; returns the smallest value from the given two numbers.

Step 1int x=3, y=4, z; The variable x, y, z are declared as an integer type and the variable x, y are initialized to value 3, 4 respectively.

Step 2z = MIN(x+y/2, y-1); becomes,

=> z = (x+y/2 < y-1)? x+y/2 : y - 1;

=> z = (3+4/2 < 4-1)? 3+4/2 : 4 - 1;

=> z = (3+2 < 4-1)? 3+2 : 4 - 1;

=> z = (5 < 3)? 5 : 3;

The macro return the number 3 and it is stored in the variable z.

Step 3if(z > 0) becomes if(3 > 0) here the if condition is satisfied. It executes the if block statements.

Step 4printf("%d\n", z);. It prints the value of variable z.

Hence the output of the program is 3

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