Question 4275 – UGC NET CS 2005 june-paper-2

After 3 calls of the c function bug( ) below, the values of i and j will be :
int j=1;
bug( )
{
static int i=0; int j=0;
i++;
j++;
return (i);
}

Correct Answer: D

Question 11 Explanation: 
Step-1: Initially i=0 but given as static. The scope is lifetime.
Step-2: Call-1: i=1 and j=1
Call-2: i=2 and j=1 because ‘i’ is static ‘j’ is again become 0 when it starts new call.
Call-3: i=3 and j=1 because ‘i’ is static ‘j’ is again become 0 when it starts new call.
Note: A static ‘int’ variable remains in memory while the program is running.
A
i = 0, j = 0
B
i = 3, j = 3
C
i = 3, j = 0
D
i = 3, j = 1

Leave a Reply

Your email address will not be published. Required fields are marked *

error: <b>Alert: </b>Content selection is disabled!!
DSSSB TGT 2021
November 16, 2023
Question 7962 – GATE 2017 [Set-2]
November 16, 2023
DSSSB TGT 2021
November 16, 2023
Question 7962 – GATE 2017 [Set-2]
November 16, 2023