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
what is pre-processor in C++?
How come you find out if a linked-list is a cycle or not?
If a function doesn’t return a value, how do you declare the function?
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.
Why namespace is used in c++?
What is ios :: in in c++?
What are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random
What do you understand by pure virtual function? Write about its use?
What is a virtual destructor? Explain the use of it?
what is friend function in C++?
What are the new features that iso/ansi c++ has added to original c++ specifications?
What are the restrictions apply to constructors and destructors?
Write about the members that a derived class can add?
What is abstraction encapsulation?
What is a linked list in c++?