POINTERS
POINTERS:
- Pointer is derived data type.
- Pointer is denoted with *.
- Pointer provide an alternative approach to access other data objects.
Declaring Pointer:
data-type *pointer-variable;
For Example:
For Example:
int *p ; //here p is pointer variable
Let's take example:
W.A.P. that illustrate the concept of pointers, also implement the arithmetic operation in pointers.
CODE:
#include <iostream>
using namespace std;
const int MAX = 3;
int main () {
int var[MAX] = {10, 100, 200};
int *p; // pointer declaration
p = var;
for (int i = 0; i < MAX; i++) {
cout << "Address of var[" << i << "] = ";
cout << p << endl;
cout << "Value of var[" << i << "] = ";
cout << *p << endl;
p++;
}
return 0;
}
OUTPUT :
0 Comments