-
Notifications
You must be signed in to change notification settings - Fork 0
/
Работа с указателями.cpp
44 lines (42 loc) · 1.33 KB
/
Работа с указателями.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
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main() {
int b = 5;
cout << "Value ( b): " << b << ", Address: " << &b << endl;
int* c = &b;
cout << "Value (*c): " << *c << ", Address: " << c << endl;
*c = 6;
cout << "Value (*c): " << *c << ", Address: " << c << endl;
cout << "Value ( b): " << b << ", Address: " << &b << endl;
b = 9;
cout << "Value (*c): " << *c << ", Address: " << c << endl;
cout << "Value ( b): " << b << ", Address: " << &b << endl;
int** d = &c;
**d = 7;
cout << "Value (*c): " << *c << ", Address: " << c << endl;
cout << "Value ( b): " << b << ", Address: " << &b << endl;
cout << endl;
cout << "**d *d d" << endl;
cout << **d << " " << *d << " " << d << endl;
cout << endl;
int arr[10];
int i;
for (i = 0; i < 10; i++) {
arr[i] = i;
cout << "a[" << i << "] = " << arr[i] << ", address: " << &arr[i] << endl;
}
cout << endl;
cout << "arr = " << arr << endl;
for (i = 0; i < 10; i++)
cout << "a[" << i << "] = " << *(arr+i) << endl;
cout << endl;
int* p = (int*) malloc(10000*sizeof(int));
cout << "Pointer: " << p << endl;
for (i = 0; i < 10000; i++)
*(p+i) = i;
realloc(p, 20000*sizeof(int));
free(p);
return 0;
}