Functions - Find Output of Program :: Discussion


13.What will be the output of the program?
A.3, 4, 4, 3
B.4, 3, 4, 3
C.3, 3, 4, 4
D.3, 4, 3, 4
Answer:  Option  B
Explanation:

Step 1int i; The variable i is declared as an global and integer type.

Step 2int fun1(int); This prototype tells the compiler that the fun1() accepts the one integer parameter and returns the integer value.

Step 3int fun2(int); This prototype tells the compiler that the fun2() accepts the one integer parameter and returns the integer value.

Step 4extern int j; Inside the main function, the extern variable j is declared and defined in another source file.

Step 5int i=3; The local variable i is defines as an integer type and initialized to 3.

Step 6fun1(i); The fun1(i) increements the given value of variable i prints it. Here fun1(i) becomes fun1(3) hence it prints '4' then the control is given back to the main function.

Step 7printf("%d,", i); It prints the value of local variable i. So, it prints '3'.

Step 8fun2(i); The fun2(i) increements the given value of variable i prints it. Here fun2(i) becomes fun2(3) hence it prints '4' then the control is given back to the main function.

Step 9printf("%d,", i); It prints the value of local variable i. So, it prints '3'.

Hence the output is "4 3 4 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