-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointers.cpp
49 lines (33 loc) · 810 Bytes
/
pointers.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* pointer:
variable that holds address of another variable
type: int*
size of all the pointer variable are similar
int* y= &x; //declaration with initialisation
if no initialization it will have garbage value
int* y; // declare
y= &x; //assign
*/
#include <iostream>
using namespace std;
int main() {
int x = 10;
int y1 = 20;
cout<< &x <<endl;
float y = 10.5;
cout<< &y <<endl;
//It doesnt work for character variables
char ch = 'A';
//Explicit Typecasing from char* to void*
cout<<(void *)&ch <<endl;
//Pointers
int *xptr;
//Store the address of a variable
xptr = &x;
cout<< &x<<endl;
cout<< xptr <<endl;
//Re-assign another address to the variable
xptr = &y1;
cout<< &y1 <<endl;
cout<<xptr<<endl;
return 0;
}