Knowee
Questions
Features
Study Tools

Point out the error line in the following program.1. #include<stdio.h>2.  int main()3.  {4.      int i;5.      for(i=5;i<1;i--);6.      break;7.      for(i=6;;i--)8.      {9.          if(i=3)10.          {11.              break;12.          }13.      }14.      for(;;)15.      break;16.      if(i -= 3)17.      printf("%d\n", i);18.      return 0;19.  }

Question

Point out the error line in the following program.1. #include<stdio.h>2.  int main()3.  {4.      int i;5.      for(i=5;i<1;i--);6.      break;7.      for(i=6;;i--)8.      {9.          if(i=3)10.          {11.              break;12.          }13.      }14.      for(;;)15.      break;16.      if(i -= 3)17.      printf("%d\n", i);18.      return 0;19.  }

🧐 Not the exact question you are looking for?Go ask a question

Solution

The errors in the program are as follows:

  1. Line 5: The for loop will not execute because the condition i<1 is false at the beginning. The initial value of i is 5 which is not less than 1.

  2. Line 6: The break statement is not inside a loop or a switch. It should be inside a loop or a switch to terminate it.

  3. Line 9: The if statement is using the assignment operator (=) instead of the equality operator (==). It should be if(i==3) to compare i with 3.

  4. Line 16: The if statement is using the compound assignment operator (-=) which subtracts 3 from i and then checks if i is non-zero. If you want to compare i with 3, it should be if(i == 3).

So, the error lines are 5, 6, 9, and 16.

This problem has been solved

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 = &num;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

1/4

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.