Pointers and Arrays

Thanks for the help
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main()
{
    int yarr[3] = { 5, 10, 15 };
    int* ptr = yarr;

    *ptr = 6;         // set yarr[0] to 14 6
    ptr++;
    *ptr = 10;      // set yarr[1] to 10
    ptr += 1; // Already at yarr[1], so we only need to go one more to get to yarr[2]
    ptr[0] = 14;        // set yarr[2] to 6 14
    
    while (ptr >= yarr)
    {
        cout << *ptr << endl;    // print values (backwards)
        ptr--;
    }
}
Line 9 is an error.
Topic archived. No new replies allowed.