Ask Question
3 June, 02:52

Which line in the following program will cause a compiler error?

1) #include

2) using namespace std;

3)

4) int main ()

5) {

6) const int MY_VAL = 77;

7) MY_VAL = 99;

8) cout << MY_VAL << endl;

9) return 0;

10) }

+1
Answers (1)
  1. 3 June, 05:07
    0
    Line number 7.

    Explanation:

    If I am not wrong, the first line in this question would be #include. That is used to add input and output stream of the program.

    if we look at the line 1,2,3. These are just the packages/definition required to start a program.

    Line 4 starts the main program and line 5 starts the block of main program. The block ends at line 10. So, there should be no error in line 4,5 and 10.

    If we look at line 6, we can see a constant integer (const int MY_VAL = 77) definition and initialization.

    The main problem is, you cannot assign a value to a constant (MY_VAL) except during initializing stage.

    Therefore, the line 6 is also true. However, this program is further trying to assign a value to constant at line 7. Therefore, the compiler will throw error (ERROR; assigning to const value).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Which line in the following program will cause a compiler error? 1) #include 2) using namespace std; 3) 4) int main () 5) { 6) const int ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers