Error: Assignment of read-only variable in C | Common C program Errors
Error “assignment of read-only variable in C” occurs, when we try to assign a value to the read-only variable i.e. constant.
In this program, a is a read-only variable or we can say a is an integer constant, there are two mistakes that we have made:
- While declaring a constant, value must be assigned – which is not assigned.
- We cannot assign any value after the declaration statement to a constant – which we are trying to assign.
Consider the program:
Output
How to fix it?
Assign value to the variable while declaring the constant and do not reassign the variable.
Correct code:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer