-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpeculiar_code.cpp
More file actions
62 lines (50 loc) · 1.8 KB
/
peculiar_code.cpp
File metadata and controls
62 lines (50 loc) · 1.8 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Online C++ compiler to run C++ program online
#include <iostream>
#include <string>
void func(int arr[]){
arr[0] = 5;
std::cout << &arr[0] << std::endl;
}
int main(){
// int a = 10;
// int b = 20;
// int* arr[] = { &a, &b };
// int** pp = arr;
// std::cout << "addresses:" << std::endl;
// std::cout << "address of arr: " << &arr << std::endl;
// std::cout << "value of pp: " << *pp << std::endl;
// // std::cout << "address of ++*pp: " << &(++*pp) << std::endl;
// std::cout << ++*pp << std::endl;
// std::cout << "address of arr: " << &arr << std::endl;
// std::cout << "address of a: " << &a << std::endl;
// std::cout << "address of b: " << &b << std::endl;
// std::cout << **pp << std::endl; // prints 10 (a)
// ++*pp; // *pp now points to b
// std::cout << **pp << std::endl; // prints 20 (b)
// int a = 3;
// int* ptr = &a;
// int** itr = &ptr;
// // std::cout << **itr << std::endl;
// std::cout << *itr << std::endl;
// std::cout << &a << std::endl;
// std::cout << ptr << " " << &a << std::endl;
// int arr[] = { 3, 7 };
// int* ptr = arr; //decay to &arr[0] !
// ptr += 1;
// arr = (arr + 1); //illegal, compile error
// std::cout << *(arr + 1) << std::endl;
// int* pointer = new int;
// *pointer = 25;
// std::cout << *pointer << std::endl;
// pointer += 1;
// std::cout << *pointer << std::endl;
// int* ptr = reinterpret_cast<int*>(&arr);
// std::cout << "Before update: " << arr[0] << std::endl;
// func(arr);
// std::cout << &arr[0] << std::endl;
// std::cout << "After update: " << arr[0] << std::endl;
// std::cout << &arr << std::endl;
// std::cout << &arr[0] << std::endl;
// int* ptr = &arr;
return 0;
}