Identify the errors in the following program.
#include <iostream>
using namespace std;
void main()
{
int i=5;
while(i)
{
switch(i)
{
default:
case 4:
case 5:
break;
case 1:
continue;
case 2:
case 3:
break;
}
i-;
}
}



Identify the errors in the following program. #include <iostream> using namespace std; vo..

Answer / hr

case 1 :
continue;
The above code will cause the following situation:
Program will be continuing while value of i is 1 and value of i is updating. So infinite loop will be created.
Correction: At last line i- should be changed as i–;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Interview Questions

Can we use THIS Pointer in static function – Reason in C++?

0 Answers  


Do you know about Agilent PRECOMPILERS. ?

0 Answers   Agilent,


Difference between Call by pointer and by reference.

0 Answers   Adobe,


Write a C++ Program to Reverse a Number using while loop.

1 Answers  


How do you write a function that can reverse a linked-list in C++?

0 Answers   IBS,






What is a constructor initializer list?

0 Answers   Amazon,


What is constant keyword in C++? Illustrate its various uses.

0 Answers   Akamai Technologies, Infogain,


Define namespace.

1 Answers  


Can we call a virtual function from a constructor?

1 Answers  


What are string library functions(syntax).

0 Answers   Accenture,


what is the difference between a pointer and a reference?

0 Answers   Amazon, Blue Star, C DAC,


What does it mean to declare a function or variable as static?

0 Answers   Amazon,


Categories