-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointer1.cpp
124 lines (85 loc) · 2.57 KB
/
pointer1.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
using namespace std;
void degerDegistirValue(int degistir) {
degistir = 5;
}
int degerDegistirReturn(int degistir) {
degistir = 5;
return degistir;
}
void degerDegistirPointer(int* degistir) {
*degistir = 5;
}
int main() {
// normal degisken tanýmlama ve adresine ulaþma
int a;
a = 5;
cout << "a'nin adresi: " << &a << endl;
cout << "a'nin boyutu: " << sizeof(a) << " byte" << endl;
cout << "a'nin degeri: " << a << endl;
// pointer tanýmlama
// pointer = gösterici
int* b = NULL;
b = &a;
*b = 2;
cout << "a: " << a << endl;
//b = (int*)0x6ffe04;
// bnin gösterdiði adresteki deðer
cout << "b'nin gosterdigi deger: " << *b << endl;
cout << "b'nin adresi: " << &b << endl;
cout << "b'nin gosterdigi adres: " << b << endl;
cout << "b'nin boyutu: " << sizeof(b) << " byte" << endl;
int* c;
cout << sizeof(c) << " byte" << endl;
// call by value
int degistirelecek = 1;
cout << "degistirelecek once " << degistirelecek << endl;
degerDegistirValue(degistirelecek);
cout << "degistirelecek sonra " << degistirelecek << endl;
// deger donduren fonksiyon
int degistirelecek2 = 1;
cout << "degistirelecek once " << degistirelecek2 << endl;
degistirelecek2 = degerDegistirReturn(degistirelecek2);
cout << "degistirelecek sonra " << degistirelecek2 << endl;
// call by reference
int d3 = 1;
cout << "degistirelecek once " << d3 << endl;
degerDegistirPointer(&d3);
cout << "degistirelecek sonra " << d3 << endl;
char* karakter = NULL;
cout << "char adres: " << &karakter << endl;
karakter = (char*)"b";
cout << *karakter << endl;
karakter = (char*)"burhan";
cout << "char adres: " << &karakter << endl;
cout << "char boyut: " << sizeof(karakter) << "byte\n";
cout << "pointera dizi ile eris " << karakter[2] << endl;
cout << karakter << endl;
string s = "burhan";
cout << s[6] << endl;
char dizi[6];
dizi[0] = 'b';
dizi[1] = 'u';
dizi[2] = 'r';
dizi[3] = 'h';
dizi[4] = 'a';
dizi[5] = 'n';
cout << "dizinin adresi " << &dizi << endl;
cout << "(dizi+1) adresi " << *(dizi+2) << endl; // dizi[2]
for (int i=0; i<6; i++) {
cout << "&dizi+" << i << " :" << &dizi+i << "boyut: " << sizeof(dizi[i])<< endl;
}
cout << "(dizi+2) " << (dizi+2) << endl;
cout << "dizi boyut: " <<sizeof(dizi) << " byte\n";
int diziSayilar[10];
for (int i=0; i<10; i++) {
diziSayilar[i] = i * 5;
}
int *pSayi;
pSayi = diziSayilar;
for (int i=0; i<10; i++) {
cout << "adresteki deger: " << *(pSayi+i) << "adres: " << (pSayi+i) << endl;
}
//cout <<"bastir" << *(int*)(0x6ffd82) << endl;
return 0;
}