Output of the C program

What is the output of the following code?
Code
  1.  

  2. #include<stdio.h>

  3. "

  4. %d      ",s);

  5.    }

  6. }

  7.  
Copyright GeekInterview.com


1) 1 2 3 4 5 6 7 8 9

2) 1 2 3 10

3) 4 5 6 7 8 9 10

4) 4 5 6 7 8 9

Showing Answers 1 - 21 of 21 Answers

Rizwan basha

  • Sep 14th, 2011
 

2) 1 2 3 10

  Was this answer useful?  Yes

Roshan

  • Sep 15th, 2011
 

0 1 2 3

  Was this answer useful?  Yes

Clever.

Answer is 3) 4 5 6 7 8 9 10

Reason:

The result of the expression s++ is the value of s *before* the increment, so the expression (s++ < 10) operates on the values 0 through 9.

In the body of the loop, s has been incremented, so the expression (s < 4 && s < 9) operates on the values 1 through 10. When s is between 1 and 3, the continue statement is executed and the loop repeats from the beginning, skipping the printf. So only the values 4 through 10 are written to standard output.

Nits: unless your compiler documentation *explicitly* lists void main() as a legal signature, use int main(void) instead.

aswinipani

  • Sep 25th, 2011
 

ans is (3)- 4 5 6 7 8 9 10

  Was this answer useful?  Yes

Abhinav kumar

  • Sep 28th, 2011
 

The result of the expression s++ is the value of s *before* the increment, so the expression (s++ < 10) operates on the values 0 through 9.


So Ans is 45678910

  Was this answer useful?  Yes

abhir

  • Sep 29th, 2011
 

ans is 456789

  Was this answer useful?  Yes

gowda

  • Oct 18th, 2011
 

The ans is 3) 4 5 6 7 8 9

  Was this answer useful?  Yes

Patil Navanath

  • Jan 31st, 2012
 

1 2 3 10

  Was this answer useful?  Yes

udaykiran

  • Feb 8th, 2012
 

Answer is 4.

  Was this answer useful?  Yes

Amit Jain

  • Mar 25th, 2012
 

Answer is 3

  Was this answer useful?  Yes

ANKUR

  • Jun 7th, 2012
 

45678910

  Was this answer useful?  Yes

Ravindra Kumar saxena

  • Jul 25th, 2012
 

45678910

  Was this answer useful?  Yes

Nupur Boral

  • Aug 16th, 2012
 

Ans:3 s++ means-first s=0 then s=s+1.so checking the initial value of s & then increment the value of s.In this way continuing this process & print the value of s.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions