In C/C++ Pointers is a variable that stores the address of another variable. In a large system, where multiple components are layered one on top of the other/are interacting very closely, it is possible to have situations where all the layers require access to a lot of shared data. In these situations, passing by pointers (references) saves a LOT of memory and time. C++ is mostly use to produced machine code and CPUs use pointers so pointer is very important in C++. The pointer variable might be belonging to any of the data type such as int, float, char, double, short etc.
For Example
int *marks;
int mymarks=100;
in above example first variable marks (strat with *) is pointer variable and second one mymarks is simple variable.
marks=&mymarks; // its mesnas we store the value of mymarks which is 100 in marks.
in simple the address of mymarks variable is store in marks as we use & sign symbol ,& symbol is used to get the address of the variable.
For example: (Simple example of display the value by using pointer variable
#include #include void main(void) { int x=100; // simple variable x hanve value 100 int *y; //pointer variable y=&x; // y store the address of x printf("%p",y) ; // display the address of x printf("%d",*y) ; // display the value which is store on the address of x which is 100 getch( ) ; }
For example: (Passing the value to function using reference (address of variable)
#include #include #include void add(int *, int *)// add is a function which //get the address of two values void main(void) { int x,y; // declaring simple varaible x and y scanf("Enter the value of x and y %d %d",&x,&y);// Get the value of x and y add(&x,&y)// Passing the address of x and y to function add getch( ) ; } void add(int *a, int *b)// This function definition in which its received two address and store in two pointer variable *a and *b { int sum; sum=*a+*b; // add the value on address a and b printf("The result is %d",sum);// Display the result }
Declaring and Initializing Local Variable in C
Declaring and Initializing Global Variable in C Language
Printf Function In C Language
Sacnf Function In C Language
for Loop in C Language
While Loop in C Language
Do While Loop in C Language
Switch Case Statement IN C
IF -Else Statement IN C
Break Statement IN C /C++
User Define Function IN C /C++
Cout/Cin Function IN C /C++
Array IN C /C++
Two Dimensional Array IN C /C++
String In IN C /C++
Pointer In IN C /C++
Const and volatile keyword IN C /C++
Class and Object in C++
Function Over Loading in C++
Character Array In C++
Constructor in C++
Operator overloading in C++
Function Templates in C++
ATM Sample Project In Simple C Language
Find Area of Shape Using Function In C++