C Programming - Const - Discussion

Discussion Forum : Const - Point Out Errors (Q.No. 6)
6.
Point out the error in the program.
#include<stdio.h>

int main()
{
    const int k=7;
    int *const q=&k;
    printf("%d", *q);
    return 0;
}
Error: RValue required
Error: Lvalue required
Error: cannot convert from 'const int *' to 'int *const'
No error
Answer: Option
Explanation:
No error. This will produce 7 as output.
Discussion:
5 comments Page 1 of 1.

Reddy priya said:   9 years ago
I think it does not produce error it's just a warning and the output is 7.

Rashi said:   9 years ago
I have also tried this one in dev C++. It will give error. But how do we know where we have to run this program. It must have to mention over there.

Akash said:   10 years ago
I have also same output, it will give error.

[Error] invalid conversion from 'const int*' to 'int*' [-f permissive].

Mohammad Mohsin said:   10 years ago
Given program will produce output like [Error] invalid conversion from 'const int*' to 'int*' in Dev CPP.

Mohini said:   1 decade ago
thats ok,as we are not changing the value of k

Post your comments here:

Your comments will be displayed after verification.