Popular Google Pages:
◕ This article is regarding
What is Pointer in C++?
How to declare a Pointer?
Last updated on: 07th October 2017.
◕ What is Pointer in C++?
While storing data, a computer program like C++ keeps track of three fundamental things.
1. Where the information is stored?
2. What value is kept there?
3. What kind of information is stored there?
int birds = 5;
Here we declare the type i.e. the kind of information which is int (integer).
The value which is kept there is 5. And the symbolic name of that value is birds.
Now where this information is stored?
The memory allocates some of its parts i.e. address or location to stored this value. It also keeps track of that location internally.
Here comes the pointer in C++.
A pointer is a variable that stores the address or the location of a variable.
To find the address or the location of a variable we have to just add the ' & ' sign before that variable.
cout << &birds << endl;
This will show the address of the variable birds like 0x0065ff28.
So a Pointer is a special type of variable which holds the address of a variable.
It represents the location of the memory.
◕ How to declare a Pointer?
Let have an example first:
int bird = 10; // This declare the variable bird.
int *nest; // This declare the pointer of the int bird.
nest = &bird; // This assigns the address or location of the int bird to the pointer nest.
// Now we can express the value of the int in two ways:
cout << " bird = " << bird <<endl;
cout << " *nest = " << *nest << endl;
// Now we can express the address of the int in two ways:
cout << " &bird = " << &bird <<endl;
cout << " nest = " << nest << endl;
The output will be like:
bird = 10
*nest = 10
&bird = 0x0065fd20
nest = 0x0065fd20
◕ Address Operator in C++?
◕ What is Structure Data Type in C++?
◕ What is the Compound Type in C++?
◕ Array in C++?
◕ Can we read include files in C++?
◕ What is bool Type in C++?
◕ What is char16_t and char32_t in C++?
◕ What is wchar_t in C++?
◕ What is Universal Character Names in C++? How to use Universal Character Names?
◕ What is Escape Sequence in C++? Complete list of Escape Sequence.
◕ Different way to create a new line in C++?
◕ What is a Member Function in C++?
◕ char Type, The Smallest Integer in C++, What is char Type?
◕ Use a constant directly into C++ program, without declaring it
◕ How to display a value in Octal form in C++?
◕ How to display a value in Hexadecimal form in C++?
Popular Google Pages:
Top of the page