You are on page 1of 1

#include <iostream>

#include <cstring>
using namespace std;
int main(){
int x = 10;
int *p; //Initialising the pointer
p = &x; //Referencing the pointer to the value stored
in x and initialising it to the value 10
x += 1; //Due to referencing increment in x value
will increase the value the pointer is pointing to as well
cout<<*p<<endl; //gives the value to which the pointer is
pointing
cout<<p<<endl; //gives the address stored in the pointer
cout<<&x<<endl;//gives the address of x
cout<<x<<endl; //gives the value stored in variable x
return 0;

int main(){
int array[3] = {3, 5, 7};
int *p = array;
//If you want to intialise the pointer to the value 5, int *p
= &array[1]
cout<<p<<endl; //gives the address of the element to
which the pointer is pointing, eg: 0x61ff00
cout<<*p<<endl; //gives the value stored in the array
to which the pointer is pointing
cout<<array<<endl; //gives the address of array (first
element, eg: 0x61ff00)
cout<<&array<<endl; //gives the address of array (first
element, eg: 0x61ff00)
// cout<<__addressof(array)<<endl;

return 0;
}

You might also like