-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpointer_typecasting.cpp
More file actions
31 lines (28 loc) · 1.07 KB
/
Copy pathpointer_typecasting.cpp
File metadata and controls
31 lines (28 loc) · 1.07 KB
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
#include <iostream>
#include <conio.h>
using namespace std;
int main(){
int index = 10; int *pointer ;
pointer = &index;
cout << "Size of integer : " << sizeof(int) << endl;
cout << "addrees :"<< pointer << " , value : " << *pointer << endl;
char *char_pointer;
char_pointer = (char *)pointer;
cout << "Size of character : " << sizeof(char) << endl;
cout << "addrees :"<< (void *)char_pointer << " , value : " << (int)*char_pointer << endl;
//-----------------> void pointer
cout <<endl<<endl<<endl<< "----------------> void pointer"<<endl<<endl ;
int value = 100; int *ptr_1;
ptr_1 = &value;
cout << "adreess of ptr 1 = " << ptr_1 << endl;
cout << "value of ptr 1 = " << *ptr_1 << endl;
cout << "value of ptr 1 + (int 8) = " << *ptr_1 + 8 << endl;
//------> add void pointer - genric pointer
void *ptr_2;
ptr_2 = ptr_1;
cout << "adreess of ptr 2 = " << ptr_2 << endl;
cout << "adreess of ptr 2 + 1 = " << ptr_2 + 1 << endl;
cout << "adreess of ptr 2 + 8 = " << ptr_2 + 8 << endl;
cout << "Note, *ptr_2 + 1 or any integer value is not possible " << endl;
getch();
}