Home Pointers
Post
Cancel

Pointers

Pointers in C++ basically store memory locations where a variable is stored.To access its value you can use * behind its name and also to declare them.The name of an array is a constant pointer.An & behind a variable gives its address.The address is displayed in hexadecimal.

1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>
using namespace std;
int main()
{
    int a=9,b[]={1,2,3,4,5},*c;
    c=&a;
    cout<<"The memory address of a is:\n"<<c<<"\nAnd its value is:\n"<<*c;
    cout<<"\nFirst element of b:\n"<<*b<<" \nThird element of b:\n"<<*(b+3);
    return 0;
}

OUTPUT:

output

This post is licensed under CC BY 4.0 by the author.

Trending Tags