GATE | GATE CS 2019 | Question 36
Consider the following C program:
#include<stdio.h> int r(){ int static num=7; return num--; } int main() { for(r();r();r()) { printf("%d ",r()); }; return 0; } |
chevron_right
filter_none
Which one of the following values will be displayed on execution of the programs?
(A) 41
(B) 52
(C) 63
(D) 630
Answer: (B)
Explanation: According to “for” loop in C,
for (initialization expr; test expr; update expr)
{
// body of the loop
// statements we want to execute
}
Code will execute as following flow chart,

Also, note that there is postdecrement (num – –) in given return statement, so it will return previous value of “num” then decrements it by 1.
Static will assign memory once for variable int “num” and all the changes will happen here.
#include<stdio.h> int r(){ int static num=7; return num--; } int main() { for(r();r();r()) { printf("%d ",r()); }; return 0; } |
chevron_right
filter_none
Therefore, given code will print: 5 2.
![]()
Option (B) is correct.
Quiz of this Question
Recommended Posts:
- GATE | GATE CS 1999 | Question 36
- GATE | GATE CS Mock 2018 | Question 39
- Top 5 Topics for Each Section of GATE CS Syllabus
- How to prepare in Last 10 days to score high in GATE?
- Aptitude | GATE IT 2006 | Question 7
- Aptitude | GATE IT 2006 | Question 8
- GATE | GATE CS 2013 | Question 1
- GATE | GATE CS 2013 | Question 3
- GATE | GATE CS 2013 | Question 4
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 6
- GATE | GATE CS 2013 | Question 7
- GATE | GATE CS 2013 | Question 8
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 65



