GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 123 of 203    Print  
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

  
Total Answers and Comments: 10 Last Update: April 09, 2008     Asked by: Rujul 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: kuldeep kumar
 
the following code results in syntax error &  compilation error due to multiple declaration for variable i.

Above answer was rated as good by the following members:
yzesong
March 10, 2007 05:23:04   #1  
swetha        

RE: the following code results in class eg ...
The following code results in system/compilation error.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 12, 2007 07:39:10   #2  
smart_coder Member Since: January 2007   Contribution: 290    

RE: the following code results in class eg ...
Compilation error. Multiple declaration of i
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 12, 2007 17:37:22   #3  
ram        

RE: the following code results in class eg ...
1. syntax / compilation error

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

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 13, 2007 07:51:50   #4  
smart_coder Member Since: January 2007   Contribution: 290    

RE: the following code results in class eg ...
i think multiple declaration of i will also create problem.. dnt u think?
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 15, 2007 02:27:13   #5  
siva sankar        

RE: the following code results in class eg ...
syntax / compilation error must occer.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 16, 2007 21:32:41   #6  
Aditya        

RE: the following code results in class eg ...
The result will be
5 7 8 9

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
March 22, 2007 23:06:36   #7  
kuldeep kumar        

RE: the following code results in class eg ...
the following code results in syntax error & compilation error due to multiple declaration for variable i.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 23, 2007 11:33:30   #8  
other        

RE: the following code results in class eg ...
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

 
Is this answer useful? Yes | No
July 23, 2007 11:14:53   #9  
Indrajit        

RE: the following code results in class eg ...
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 ?

 
Is this answer useful? Yes | No
April 09, 2008 23:03:35   #10  
vinthri Member Since: April 2008   Contribution: 2    

RE: the following code results in class eg { void ml( ) {int i = 6; for {int i=5: i< 10;i ++ } { if{i==6} continue; system
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

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape