An array a contains 5 int values. What is the type of *a?

SUMMARY

Let an array ‘a’ contains 5 int values. ‘a’ will then have the base address of the array, which is the address of the first element in the array. So *a would give the element in ‘a’, which is the first element.

 

EXPLANATION

Any pointer which points to the integer having the address and the * of that address would give the value stored in that address.

So, the value of the *a would be the 1st element of the array.

#include<iostream>
using namespace std;

int main()

{
    int a[5] = {2,4,6,8,10};

    cout<<"elements of the array:"<<endl;

    for(int j=0;j<5;j++)

    cout<<a[j]<<"";

    cout<<endl<<endl;

    cout<<"value of *a="<<*a<<endl;

    cout<<"value of *(a+1)="<<(a+1)<<endl;

    cout<<"value of *(a+2)="<<(a+2)<<endl;

    cout<<"value of *(a+3)="<<(a+3)<<endl;

    cout<<"value of *(a+4)="<<(a+4)<<endl;

}

 

OUTPUT

Elements of the array :

2 4 6 8 10 

value of *a = 2

value of *(a+1)=4

value of *(a+2)=6

value of *(a+3)=8

value of *(a+4)=10

 

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *