Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the following c-program​#inclu... Start Learning for Free
Consider the following c-program ​
#include <stdio.h>
int r(){
static int num=7;
return num --; }
int main(){
for (r();r();r())
printf("%d",r());
return 0; }
Which one of the following values will be displayed on execution of the programs?
  • a)
    52
  • b)
    630
  • c)
    41
  • d)
    63
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
Consider the following c-program​#include <stdio.h>int r()...
for (r();r();r())
for initialization r() function will execute num will become 6
for conditional checking r() will execute and num will be 5
body of the loop executed and return value will be 5 and hence 5 will be printed
increment part of the loop will be executed as r() and value will be 3
again condition will be tested as r() num will be 2
body of the loop will print as r(), 2 will be printed value decremented to 1
loop will break
final value printed is 52
View all questions of this test
Most Upvoted Answer
Consider the following c-program​#include <stdio.h>int r()...
First, let's analyze the given code:
- **r() function**: This function is a static function that returns the value of a static variable `num` decremented by 1 each time it is called.
- **main() function**: In the `main()` function, a `for` loop is used to call the `r()` function three times. The loop condition `r()` will return 7, 6, and 5 respectively in the first three iterations.
- **printf statement**: Inside the loop, the `printf()` statement will print the value returned by `r()` after decrementing it by 1. So, the output will be 6, 5, and 4 respectively.
Now, let's trace the values returned by the `r()` function during the execution of the program:
1. The first call to `r()` in the `for` loop will return 7, but it will not be printed.
2. The second call to `r()` in the loop condition will return 6, and it will be printed.
3. The third call to `r()` in the loop condition will return 5, and it will be printed.
4. The fourth call to `r()` in the loop condition will return 4, and it will be printed.
Therefore, the values displayed on execution of the program will be **52**.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Consider the following c-program​#include <stdio.h>int r(){static int num=7;return num --; }int main(){for (r();r();r())printf("%d",r());return 0; }Which one of the following values will be displayed on execution of the programs?a)52b)630c)41d)63Correct answer is option 'A'. Can you explain this answer?
Question Description
Consider the following c-program​#include <stdio.h>int r(){static int num=7;return num --; }int main(){for (r();r();r())printf("%d",r());return 0; }Which one of the following values will be displayed on execution of the programs?a)52b)630c)41d)63Correct answer is option 'A'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the following c-program​#include <stdio.h>int r(){static int num=7;return num --; }int main(){for (r();r();r())printf("%d",r());return 0; }Which one of the following values will be displayed on execution of the programs?a)52b)630c)41d)63Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following c-program​#include <stdio.h>int r(){static int num=7;return num --; }int main(){for (r();r();r())printf("%d",r());return 0; }Which one of the following values will be displayed on execution of the programs?a)52b)630c)41d)63Correct answer is option 'A'. Can you explain this answer?.
Solutions for Consider the following c-program​#include <stdio.h>int r(){static int num=7;return num --; }int main(){for (r();r();r())printf("%d",r());return 0; }Which one of the following values will be displayed on execution of the programs?a)52b)630c)41d)63Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the following c-program​#include <stdio.h>int r(){static int num=7;return num --; }int main(){for (r();r();r())printf("%d",r());return 0; }Which one of the following values will be displayed on execution of the programs?a)52b)630c)41d)63Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following c-program​#include <stdio.h>int r(){static int num=7;return num --; }int main(){for (r();r();r())printf("%d",r());return 0; }Which one of the following values will be displayed on execution of the programs?a)52b)630c)41d)63Correct answer is option 'A'. Can you explain this answer?, a detailed solution for Consider the following c-program​#include <stdio.h>int r(){static int num=7;return num --; }int main(){for (r();r();r())printf("%d",r());return 0; }Which one of the following values will be displayed on execution of the programs?a)52b)630c)41d)63Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of Consider the following c-program​#include <stdio.h>int r(){static int num=7;return num --; }int main(){for (r();r();r())printf("%d",r());return 0; }Which one of the following values will be displayed on execution of the programs?a)52b)630c)41d)63Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following c-program​#include <stdio.h>int r(){static int num=7;return num --; }int main(){for (r();r();r())printf("%d",r());return 0; }Which one of the following values will be displayed on execution of the programs?a)52b)630c)41d)63Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev