Arrays - Find Output of Program :: Discussion


1.What will be the output of the program?
A.2, 1, 15
B.1, 2, 5
C.3, 2, 15
D.2, 3, 20
Answer:  Option  C
Explanation:

Step 1int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an integer array with a size of 5 and it is initialized to

a[0] = 5a[1] = 1a[2] = 15a[3] = 20a[4] = 25 .

Step 2int i, j, m; The variable i,j,m are declared as an integer type.

Step 3i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2

Step 4j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.

Step 5m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by 1(i++ means 2++ so i=3)

Step 6printf("%d, %d, %d", i, j, m); It prints the value of the variables i, j, m

Hence the output of the program is 3, 2, 15

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