SPOT THE ERROR....!

Mar 12, 2014 at 7:23pm
Hi,
I have a life changing exam today(its 12.45am here). Now i bumped in a sample question i have collected. It prompts to correct the error but i cant find any... Can you please help me..
1
2
3
4
5
6
int i,p[]={1,2,3,4};
for(i=0;i<4;i++)
{
 cout<<*p;
 p++;
} 


I know that 'p' points to case address of array and can't find any problems with pointer arithmetic... Please help. Thanks for patience...
Last edited on Mar 13, 2014 at 2:49am
Mar 12, 2014 at 8:06pm
You can't increment p, either copy it[1] or use i[2]:
[1] http://ideone.com/WoCCGI
[2] http://ideone.com/PElFFQ
Mar 12, 2014 at 10:20pm
why cant you increment p?
Mar 12, 2014 at 11:01pm
An array name isn't the same as a pointer, it isn't an lvalue http://ideone.com/UE5Ujy
http://www-ee.eng.hawaii.edu/~tep/EE160/Book/chap7/subsection2.1.3.2.html
Mar 13, 2014 at 2:48am
oh,Thanks guys I never knew that fact....Now i can nail that kinda questions....Thanks all...
Topic archived. No new replies allowed.