What will happen when the following code is run:
int x;
while(x<100)
{
cout<<x;
x++;
}




1) The computer will output "0123...99"


2) The computer will output "0123...100"


3) The output is undefined

Answers were Sorted based on User's Feedback



What will happen when the following code is run: int x; while(x<100) { cout<<x; x++; ..

Answer / nk

Output is undefined because initially variable 'x' is not
initialized and may contain some garbage value.

However if we initialize 'x' to 0 then choice#1 is correct.

Is This Answer Correct ?    13 Yes 0 No

What will happen when the following code is run: int x; while(x<100) { cout<<x; x++; ..

Answer / d n gavade

The Answer is 3)The Output is undefined because x is not
initialised and its datatype is auto int so that its inital
value will be garbage.

Is This Answer Correct ?    3 Yes 0 No

What will happen when the following code is run: int x; while(x<100) { cout<<x; x++; ..

Answer / deepanker aggarwal

the answer is 3 because x is not initialised and it may
contain any garbage value

Is This Answer Correct ?    1 Yes 0 No

What will happen when the following code is run: int x; while(x<100) { cout<<x; x++; ..

Answer / rakesh

the output is undefined
because c++ do not implicitly initialised the varible. it
gives garbage value for uninitialized variables

Is This Answer Correct ?    1 Yes 0 No

What will happen when the following code is run: int x; while(x<100) { cout<<x; x++; ..

Answer / ibrazileasum

The initial value of x is not defined to '0' hence the complier will not start from 0 as initial value. This is a garbage error to the compiler

Is This Answer Correct ?    0 Yes 0 No

What will happen when the following code is run: int x; while(x<100) { cout<<x; x++; ..

Answer / aravind

In most of the compilers now all declared variables are
usually initialised with 0. So in most compilers result
would be #1. But in some cases the garbage values may creep
up.

Is This Answer Correct ?    0 Yes 1 No

What will happen when the following code is run: int x; while(x<100) { cout<<x; x++; ..

Answer / sanish joseph

ans s absolutely right..

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More OOPS Interview Questions

Why do we use polymorphism?

0 Answers  


i got a backdoor offer in process global,Bangalore..Can i work with it?

0 Answers  


What are the 4 main oop principles?

0 Answers  


What is the difference between abstraction and polymorphism?

0 Answers  


Give two or more real cenario of virtual function and vertual object

0 Answers   TCS,






What is class and object in oops?

0 Answers  


What do you mean by multiple inheritance and multilevel inheritance? Differentiate between them.

2 Answers  


write a C++ program for booking using constructor and destructor.

0 Answers   HAL,


Why static Function is used in C++?

4 Answers   TCS,


Why multiple inheritance is not possible?

0 Answers  


design a c++ class for the chess board,provide a c++ class definition for such class(only class definition is required)

0 Answers   UBS,


I am developing a payroll system mini project.I used file concept in program for reading and writing.When the program is reloading into the memory that is if i execute next time the file was cleaned and adding data from the starting this is my problem.I want to strore the previous data and if i want to add any record that should be next of previous data.Please help me.

0 Answers  


Categories