explaining output of given program

Following program is given.pl tell me what will be output of this program and also explain how to get it
void main ( )
{ int Track [ ] = {10, 20, 30, 40}, *Striker ;
Striker=Track :
Track [1] += 30 ;
cout<<"Striker>"<<*Striker<<endl ;
Striker – =10 ;
Striker++ ;
cout<<"Next@"<<*Striker<<endl ;
Striker+=2 ;
cout<<"Last@"<<*Striker<<endl ;
cout<< "Reset To" <<Track[0] <<endl ;

Last edited on
Which bits of it are you having trouble understanding?

As im a beginner at c++ and i was learning pointers so it would be really helpful if you could explain the output from the starting and also in my book, answer to the program was given as follows but i really dont have any idea how this came.


Reset to 0


Pointer to Track[0]
Pointer to Track[1]
Pointer to Track[3]
Value at Track[0]
The following statement in your program is going to cause a problem:
Striker – =10 ; 

That's going to subtract 10 from the pointer Striker resulting in a reference to Track[-10] which is out of bounds of the array.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
Topic archived. No new replies allowed.