#include <iostream>
#define n 255
using namespace std;
int main()
{
int i=n;
int *ptr=&i;
int const *ptr_1=&i;
const int *ptr_2=&i;
const int * const ptr_3=&i;
}
Why does this Code Compile in Visual C++, Dev C++ and G++?
Link to – Ideone –
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It does compile, because all those pointers ether don’t change
const-qualification of the variable access or enforce the qualification, but none of them tries to loosen the qualification.For example:
would try to get non-const access to a const variable and that’s illegal, but
tries to get const access to a non-const variable and that’s legal since a non-const variable does allow const-only access.