Answer to Question #147615 in C++ for Usama Saleem

Question #147615
Mention all the errors in the following code:
#include <iostream>
using namespace std;
int main()
{
const int x;
x = 10;
cin >> y;
int y = 10;
cout << x << " " << y;
return 0
}
1
Expert's answer
2020-11-29T23:49:09-0500

Errors:

i) const int x;  - uninitialized const ‘x’
ii) x = 10;      - assignment of read-only variable ‘x’
iii) cin >> y;   - ‘y’ was not declared in this scope
iv) return 0     - expected ‘;’ before ‘}’ token

The correct code would be:

#include <iostream>

using namespace std;

int main()
{
    const int x = 10;
    
    int y = 10;
    
    cin >> y;
    
    cout << x << " " << y;
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog