General pointer question? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

General pointer question?

if I am declaring Int *x; Int n=5; *x=&n; why it is showing error explain?

15th Jul 2017, 5:48 AM
Vignesh r
Vignesh r - avatar
2 Answers
+ 6
*x = &n is a common mistake made by beginners when dealing with pointers. The 'point-to' operator should not be used here. Do x = &n; You want to assign the address of n to pointer x, and not to the value pointed by pointer x. Try referring to this code: https://code.sololearn.com/c7mW3DQoz3m0/?ref=app
15th Jul 2017, 6:07 AM
Hatsy Rei
Hatsy Rei - avatar
+ 11
*x=n or x=&n both are correct.
15th Jul 2017, 6:09 AM
Prabhu Nithin
Prabhu Nithin - avatar