Why *(a++) is not working in main function ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
29th Mar 2022, 7:57 AM
Abhay mishra
Abhay mishra - avatar
3 Answers
+ 4
In main, the "a" is not a pointer, you need to do this:- printf ("0 = %d\n" , *a) ; printf ("1 = %d\n" , *(a+1);
29th Mar 2022, 8:44 AM
rodwynnejones
rodwynnejones - avatar
+ 3
Array notation won't advance on pre/post increment like pointer notation does. Try this? https://code.sololearn.com/cF918k4igw2j/?ref=app
29th Mar 2022, 10:32 AM
HungryTradie
HungryTradie - avatar
+ 2
I'm not sure I can explain, but it probably has something to do with operator precedence, because post & pre increment operator has higher precedence over indirection (dereference) operator. It works fine if we use an actual int* though. Just be sure to pass the pointer (not using address-of operator &) when passing the pointer to `fun` function. Let's wait for others' opinions ...
29th Mar 2022, 8:08 AM
Ipang