pointer in c++ with examples

Image result for c++Going forward with this C/C++ programming language tutorial today we will learn pointer which is considered most difficult in C/C++.

What is Pointer in C/C++ programming language

Earlier we have seen how any variable is stored in memory. Address of variable tells where variable is stored in memory. This address is called pointer. C/C++ gives us facility know the address of variable where its value is stored. To know address of any variable & is used. For example if variable is int x; then &x will give address of x. As we store any variable int, char, float etc similarly address of any variable can also be stored. There is new datatype which is used to store address of variable. To store address of int variable int* datatype is used. similarly to store address of char variable char* datatype is used. Example given below shows how to store address of variable.
int x = 5;
int* p;
p = &x
Here int variable x define, Then variable p is declared which can store address of any int variable. Then we have assigned address of x to p variable.
Address→01234
Memory→100001111110010100100110000010101100101. . . 
p = &x = 3int x
Now we have variable p which is of int* type and address of x is stored in it - means if we print p, address of x will be print.( As shown above here address of x is 3 running program at different time, address of x will change.) If we want to know what is stored in the Memory pointed by p then *p is used(Here p address of memory where x is and value there is 5 hence *p will give 5 here). lets see an small example. Change this example as per yourself and run it. do experiments. 
#include <stdio.h>

int
main() {
int
x = 5;
int
* p = &x;
printf("x = %d\n",x);
printf("address of x = %d\n", p);
printf("value at location p = %d\n", *p);

scanf("%d", &x);
return
0;
}