Ask Question
8 June, 05:31

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

+2
Answers (1)
  1. 8 June, 08:44
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers