Are these two equivalent?
int a=10;
int *p=a;
AND
int a=10;
int *p;
p=&a;
Does p hold address of a in both the cases!?
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.
In the first case
The value contained in the variable a is put into the variable p. So the value of the variable p is 10.
In the second case
The value in the variable a is 10 and the value in the variable p is the address of a.
In the first case even though the variable p is declared as a pointer to an int the value being put into the variable p is the value of the variable a, a value of 10. In the second case you are putting the address of the variable a into the variable p.