Functions - Find Output of Program :: Discussion


2.What will be the output of the program?
A.5, 2
B.10, 4
C.2, 5
D.25, 4
Answer:  Option  D
Explanation:

Step 1int i=5, j=2; Here variable i and j are declared as an integer type and initialized to 5 and 2 respectively.

Step 2fun(&i, &j); Here the function fun() is called with two parameters &i and &j (The & denotes call by reference. So the address of the variable i and j are passed. )

Step 3void fun(int *i, int *j) This function is called by reference, so we have to use * before the parameters.

Step 4*i = *i**i; Here *i denotes the value of the variable i. We are multiplying 5*5 and storing the result 25 in same variable i.

Step 5*j = *j**j; Here *j denotes the value of the variable j. We are multiplying 2*2 and storing the result 4 in same variable j.

Step 6: Then the function void fun(int *i, int *j) return back the control back to main() function.

Step 7printf("%d, %d", i, j); It prints the value of variable i and j.

Hence the output is 25, 4.

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