Pointers and Array in C plus plus programming language

Pointers and Array in C plus plus programming language

Instructor-svgAl-Mamun Sarkar
Apr 03 , 2020

Pointers and Array in C plus plus programming language. The following code shows how pointer and array work in C plus plus Programming Language.

 

Code:

#include<iostream>
using namespace std;

int main()
{
    int A[] = {2, 4, 8, 6, 98, 12};

    cout << "Output of of A : " << A << endl;
    cout << "Output of of &A[0] : " << &A[0] << endl;

    // Print First Element of an array
    cout << "Output of of *A : " << *A << endl;
    cout << "Output of of A[1] : " << A[0] << endl;

    // Print 4th Element of an array
    cout << "Output of of *A : " << *(A+3) << endl;
    cout << "Output of of A[1] : " << A[3] << endl;


    int *p = A;
    // Print 4th Element of an array
    cout << "Output of of *p : " << *p << endl;
    p++;
    cout << "Output of of *p : " << *p << endl;
    cout << "Output of of p++ : " << *(++p) << endl;

    return 0;
}

 

Output:

Output of of A : 0x7ffee1d11a50
Output of of &A[0] : 0x7ffee1d11a50
Output of of *A : 2
Output of of A[1] : 2
Output of of *A : 6
Output of of A[1] : 6
Output of of *p : 2
Output of of *p : 4
Output of of p++ : 8

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram