The following code results in class eg { void ml( ) {int i = 6; for {int i=5: i< 10;i ++ } { if{i==6} continue; system.out.println {i} ; } } ; } 1. syntax / compilation error 2. 5 6 7 8 9 3. 6 7 8 9 4. 5 7 8 9

Questions by Rujul   answers by Rujul

Showing Answers 1 - 34 of 34 Answers

swetha

  • Mar 10th, 2007
 

 The following code results in system/compilation error.

ram

  • Mar 12th, 2007
 

1. syntax / compilation error

it is not int i declaratin problem.
println() is nor properly called.

siva sankar

  • Mar 15th, 2007
 

 syntax / compilation error must occer.

Aditya

  • Mar 16th, 2007
 

The result will be
5,7,8,9

kuldeep kumar

  • Mar 22nd, 2007
 

the following code results in syntax error &  compilation error due to multiple declaration for variable i.

other

  • Mar 23rd, 2007
 

not only that...but the for loop has its conditionals in {} rather than ()
and that goes for println as well.....
further, the last semi colon should go outside the class declaration, not before the last }

-c

Indrajit

  • Jul 23rd, 2007
 

The multiple declaration of int i is not a problem in C++ since the scopes of the two i's are different (the second i is valid only inside the for loop and overrides the first i inside the loop).

and system.out.println is java...wonder what that is doing as part of C++ interview questions and why none has pointed it out before ?

  Was this answer useful?  Yes

vinthri

  • Apr 9th, 2008
 

compilation error.
Quite valid as stated by many above, the curly braces is one issue.
the other issue i notice is after the assignment of i in the "for"  loop assignment operator, there should be semi colon and not colon

  Was this answer useful?  Yes

If you see the for for block:
for {int i=5: i< 10;i ++ }
you will see that it has a semi colon after the int i=5 which results in a syntax error. so the answer would be 1. syntax/compilation error

  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