Point out the error line in the following program. 1. #include<stdio.h> 2. int main() 3. { 4. int i = 1; 5. switch(i) 6. { 7. printf("This is c program."); 8. case 1: 9. printf("Case1"); 10. break; 11. case 2 12. printf("Case2"); 13. break; 14. } 15. return 0; 16. }
Question
Point out the error line in the following program. 1. #include<stdio.h> 2. int main() 3. { 4. int i = 1; 5. switch(i) 6. { 7. printf("This is c program."); 8. case 1: 9. printf("Case1"); 10. break; 11. case 2 12. printf("Case2"); 13. break; 14. } 15. return 0; 16. }
Solution
The error is in line 7. The "printf" statement is not inside any case. In a switch statement, all code should be inside a case or default block. Here is the corrected code:
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
case 1:
printf("This is c program.");
printf("Case1");
break;
case 2:
printf("Case2");
break;
}
return 0;
}
Similar Questions
When the following code is executed an error is encountered and the program crashes. On which line do you think the error is encountered?You may assume that all required classes have been defined elsewhere.
When a program runs, but does not do what you expect, it means that your progam contains…?Logical ErrorSyntax error
Point out the error line in the following program.1 #include <iostream>2 using namespace std;3 void main()4 {5 long int num = 10; 6 long int *ptr; 7 cout<<"num's address :"<< &num<<"\n"; 8 ptr = #9 cout<<"pointer's address :"<< &ptr<<"\n"; 10 cout<<"pointer's size bytes "<< sizeof(ptr)<<"\n"; 11 cout<<"pointer's value: "<< ptr<<"\n"; 12 cout<<"value pointed to: "<< *ptr<<"\n"; 13 return 0;14 }Select one:Line number 5Line number 12Line number 3Line number 10
What will be the output of the C program? ACompilation errorB1C5DRuntime error
What is an error that occurs during the execution of code?1 pointError messagesExceptionException handlingFinally
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.