...
Operating-Systems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023
Operating-Systems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023

Programming-for-Output-Problems

Question 4

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
41
B
63
C
52
D
630
Question 4 Explanation: 
///////////////////////////PROGRAM
#include
int r()
{
int x;
static int num=7;
x =num–;
printf(“num–: %d\n”,x);
return x;
}
int main()
{
for(r(); r(); r())
{
printf(“%d\n”, r());
}
return 0;
}
//////////////////////////////OUTPUT
num–: 7
num–: 6
num–: 5
5
num–: 4
num–: 3
num–: 2
2
num–: 1
num–: 0
Correct Answer: C
Question 4 Explanation: 
///////////////////////////PROGRAM
#include
int r()
{
int x;
static int num=7;
x =num–;
printf(“num–: %d\n”,x);
return x;
}
int main()
{
for(r(); r(); r())
{
printf(“%d\n”, r());
}
return 0;
}
//////////////////////////////OUTPUT
num–: 7
num–: 6
num–: 5
5
num–: 4
num–: 3
num–: 2
2
num–: 1
num–: 0
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!