Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

pointers and arrays in c++

#include <iostream>

using namespace std;

int main()
{
    int x[3] = { 5,9,20 };
    int* p = x;
    cout << p << endl;               //prints the address of x[0]
    cout << *p << endl;             //prints the value of x[0] (5)
    //printing the array
    for (int i = 0; i < 3; i++){
        cout << p[i] << endl;
        //or
        cout << *(p + i) << endl;
    }

}
 
PREVIOUS NEXT
Tagged: #pointers #arrays
ADD COMMENT
Topic
Name
2+3 =