Pointers
Pointers
Pointers
TEXT FILE
HANDLING
VKS-LEARNING HUB
cout<<"Dec="<<hi<<","<<"Dec="<<di<<endl;
cout.setf(ios::hex, ios::basefield);
cout<<"Hex="<<hi<<","<<"Hex="<<di<<endl;
}
Pointer
a b Variable Names
Pointer Variable
To store an address of a variable we need to create a special
type of variable called Pointer variable. Creating a Pointer
variable is similar to creating a variable of fundamental data
type or array type.
.
VKS-LEARNING HUB
Pointer Declaration
Thus, the character * can appear
anywhere between the data type
name and the variable name.
VKS-LEARNING HUB
Pointer Declaration
int* p, q;
In this statement:
only p is the pointer variable, not q.
Here, q is an int variable.
we prefer to attach the character * to
the variable name. So the preceding
statement is written as:
int *p, q;
VKS-LEARNING HUB
Pointer Operators
C++ provides two operators operator
to work with pointers.
Dereferencing Operator
(*)
VKS-LEARNING HUB
Dereferencing Operator
(*)
Consider the following statements.
1. num = 78;
2. p = #
3. *p = 24;
VKS-LEARNING HUB
Example
#include <iostream.h>
#include <string>
//===============================
void main() {
int *p;
int x = 37;
cout <<"x= " << x<<endl;
p=&x;
cout <<"*p= "<< *p <<" , x= "<<x<<endl;
*p=85;
cout <<"*P= " <<*p <<" , x= "<<x<<endl;
cout <<" Address of p is : "<< &p <<endl;
cout<<"value of p : "<< p<<endl;
cout<< " value of memory location pointed to by *p = "<<*p<<endl;
cout<<"Address of X = " << &x<<endl;
cout <<" Value of x = " << x<<endl;
}
VKS-LEARNING HUB
VKS-LEARNING HUB
VKS-LEARNING HUB