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

How can a C function be called in a C++ program?

0 Answers  


Identify the error in the following program. #include<iostream.h> void main() { int i = 0; i = i + 1; cout « i « " "; /*comment *//i = i + 1; cout << i; }

1 Answers  


Can we provide one default constructor for our class?

0 Answers  


What is the difference between realloc() and free() in C++?

0 Answers   IBS, TCS,


If class D is derived from a base class B

0 Answers  


CDPATH shell variable is in(c-shell)

0 Answers   Siemens,


When must you use a constructor initializer list?

0 Answers   Amazon,


What is an algorithm (in terms of the STL/C++ standard library)?

0 Answers   Amazon,


How many times will this loop execute? Explain your answer.

0 Answers  


Explain about Searching and sorting algorithms with complexities

0 Answers   Accenture,


What are the advantages and disadvantages of B-star trees over Binary trees?

0 Answers  


What are the costs and benefits of using exceptions?

0 Answers   Amazon,


Categories