DSSSB TGT 2021
November 16, 2023Question 7962 – GATE 2017 [Set-2]
November 16, 2023Question 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.
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.
i = 0, j = 0
i = 3, j = 3
i = 3, j = 0
i = 3, j = 1
Subscribe
Login
0 Comments