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-;
}
}

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

what is pre-processor in C++?

682


How come you find out if a linked-list is a cycle or not?

658


If a function doesn’t return a value, how do you declare the function?

705


a program using one dimensional array that searches a number if it is found on the list of given input numbers given by the user and locate its exact location in the list.

1468


Why namespace is used in c++?

698






What is ios :: in in c++?

735


What are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random

760


What do you understand by pure virtual function? Write about its use?

668


What is a virtual destructor? Explain the use of it?

635


what is friend function in C++?

677


What are the new features that iso/ansi c++ has added to original c++ specifications?

676


What are the restrictions apply to constructors and destructors?

729


Write about the members that a derived class can add?

655


What is abstraction encapsulation?

749


What is a linked list in c++?

653