in DS
529 views
0 votes
0 votes
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?

 

41

52

63

630
in DS
529 views

5 Comments

you're just wasting your time by spending on testseries instead of solving PVQ.
2
2

@Shaik Masthan Sir, what I am doing is solving previous year's questions of all subjects. Haven’t solved the full mock test and not even a subject mock test. I spend my whole day presently on PYQ, have plans to do the mock test from Jan onwards. Presently what I do is skim through all answers and comments of PYQ and keep on noting what seems new to me. But because of that, on per daily basis, I am able to solve atmost 40 questions. Am I utilizing my time correctly Sir? 

1
1

@ankit3009 that's good. even though you're looking atmost 40 questions, reading the discussion makes you better understanding the questions.

1
1
Okay thank you Sir :)
1
1

Great strategy @ankit3009 

1
1

1 Answer

0 votes
0 votes

52

For loop has following order of execution :

  1. Initialization 
  2. Condition evaluation 
  3. Execute the body if condition is true, else exit
  4. Updation
  5. Repeat steps 2 to 4 until the loop terminates.

On every step from 1 to 4, function r() is being called, which decrements the value of static variable and returns the updated value. But we are using post decrement unary operator. Hence, the value will be returned first and then updated. 

2 Comments

Yes.Correct.
1
1
just like while loop execution.
0
0

Related questions

0 votes
0 votes
1 answer
1
rsansiya111 asked in DS Dec 19, 2021
278 views
rsansiya111 asked in DS Dec 19, 2021
278 views
0 votes
0 votes
1 answer
2
rsansiya111 asked in DS Dec 17, 2021
305 views
rsansiya111 asked in DS Dec 17, 2021
305 views
0 votes
0 votes
1 answer
3
rsansiya111 asked in DS Dec 16, 2021
376 views
rsansiya111 asked in DS Dec 16, 2021
376 views
0 votes
0 votes
1 answer
4
rsansiya111 asked in DS Dec 16, 2021
336 views
rsansiya111 asked in DS Dec 16, 2021
336 views