-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_pointers.cpp
More file actions
34 lines (24 loc) · 913 Bytes
/
cpp_pointers.cpp
File metadata and controls
34 lines (24 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;
int main ()
{
long int var = 20; // actual variable declaration.
long int *ip; // pointer variable
ip = &var; // store address of var in pointer variable
cout << "Value of var variable: ";
cout << var << endl;
// print the address stored in ip pointer variable
cout << "Address stored in ip variable: ";
cout << ip << endl;
// print the address stored in ip pointer variable
cout << "Address stored in ip variable: ";
cout << ip+1 << endl; // It become + 4 ( When it was int // if it was long int, it plus 4 automatically )
// access the value at the address available in pointer
cout << "Value of *ip variable: ";
cout << *ip << endl;
cout << "Value of *ip variable: ";
cout << *ip+1 << endl;
cout << "Value of *ip variable: ";
cout << *(ip+1) << endl; // It's null.. why?
return 0;
}