explaining output of given program

Feb 24, 2013 at 11:54am
Following program is given.pl tell me what will be output of this program and also explain how to get it
#include<iostream.h>
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 Feb 24, 2013 at 11:59am
Feb 24, 2013 at 11:59am
Which bits of it are you having trouble understanding?

Feb 24, 2013 at 12:10pm
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.

output:

Striker>10
Next@50
Last@40
Reset to 0

Feb 24, 2013 at 1:06pm
Output:

Pointer to Track[0]
Pointer to Track[1]
Pointer to Track[3]
Value at Track[0]
Feb 24, 2013 at 3:58pm
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.