Skip to content

Instantly share code, notes, and snippets.

@roktas
Created May 20, 2024 09:00
Show Gist options
  • Save roktas/5dfee32f6cea33dfb66db083bdcedd88 to your computer and use it in GitHub Desktop.
Save roktas/5dfee32f6cea33dfb66db083bdcedd88 to your computer and use it in GitHub Desktop.
C dersinde verilen örnek
int a[] = {
56,
32,
7,
-4,
0,
103,
21,
-75
};
KABUL 1: Bir tam sayı (int) 32 bit, 4 B boyutunda
KABUL 2: Bir bellek hücresi 32 bit, 4 B boyutunda
1001 ???1001
1002 ???1002
1003 --- a[0] 56
1004 a[1] 32
1005 a[2] 7
1006 a[3] -4
1007 a[4] 0
1008 a[5] 103
1009 a[6] 21
1010 --- a[7] -75
1011 ???1011 BAŞKA BİR PROGRAMIN BAŞLANGICI (YANİ PROGRAMIN İLK KOMUTU)
1012 ???1012
void task(int a[], int len)
{
a ------> &a[0] -------> 1003
for (int i = 0; i < len; i++) {
a[i]++; ---> a[i] = a[i] + 1 ---> *(a + i) = *(a + i) + 1 ---> *(&a[0] + i) = *(&a[0] + i) + 1 --> *(1003 + i) = *(1003 + i) + 1
a[0]++; ---> a[0] = a[0] + 1 ---> *(a + 0) = *(a + 0) + 1 ---> *(&a[0] + 0) = *(&a[0] + 0) + 1 --> *(1003 + 0) = *(1003 + 0) + 1
a[1]++; ---> a[1] = a[1] + 1 ---> *(a + 1) = *(a + 1) + 1 ---> *(&a[0] + 1) = *(&a[0] + 1) + 1 --> *(1003 + 1) = *(1003 + 1) + 1
...
a[7]++; ---> a[7] = a[7] + 1 ---> *(a + 7) = *(a + 7) + 1 ---> *(&a[0] + 7) = *(&a[0] + 7) + 1 --> *(1003 + 7) = *(1003 + 7) + 1
HATA a[8]++; ---> a[8] = a[8] + 1 ---> *(a + 8) = *(a + 8) + 1 ---> *(&a[0] + 8) = *(&a[0] + 8) + 1 --> *(1003 + 8) = *(1003 + 8) + 1
*(1011) = *(1011) + 1
*(1011) = ???1011 + 1
}
}
task(a, 9); -> task(&a[0], 9)
int a[] = {
56,
32,
7,
-4,
0,
103,
21,
-75
};
KABUL 1: Bir tam sayı (int) 32 bit, 4 B boyutunda
KABUL 2: Bir bellek hücresi 16 bit, 2 B boyutunda
1001 ???1001
1002 ???1002
1003 --- a[0] 56 00000000
1004 00011100
1005 a[1] 32
1006
1007 a[2] 7
1008
1009 a[3] -4
1010
1011 a[4] 0
1012
1013 a[5] 103
1014
1015 a[6] 21
1016
1017 --- a[7] -75
1018
1019 ???1019
1020 ???1020
int *p = 10003456
p + 5000 sonucu 10008456 OLMAYABİLİR
Mesela bellek hücresi 2 B, tam sayı 4 B ise
p + 5000 -> p + 2 * 5000 -> 10013456
a[i] ---> *(a + i) ---> *(&a[0] + i *(a dizisinin bir elemanının adres hücresi cinsinden boyutu: KAP)
void task(int a[], int len)
{
a ------> &a[0] -------> 1003
İLK ANDA AKLA GELEN
for (int i = 0; i < len; i++) {
a[i]++; ---> a[i] = a[i] + 1 ---> *(a + i) = *(a + i) + 1 ---> *(&a[0] + i) = *(&a[0] + i) + 1 --> *(1003 + i) = *(1003 + i) + 1
a[0]++; ---> a[0] = a[0] + 1 ---> *(a + 0) = *(a + 0) + 1 ---> *(&a[0] + 0) = *(&a[0] + 0) + 1 --> *(1003 + 0) = *(1003 + 0) + 1
a[1]++; ---> a[1] = a[1] + 1 ---> *(a + 1) = *(a + 1) + 1 ---> *(&a[0] + 1) = *(&a[0] + 1) + 1 --> *(1003 + 1) = *(1003 + 1) + 1
*(1004) = *(1004) + 1 !!!!!!! HATALI YORUM
...
a[7]++; ---> a[7] = a[7] + 1 ---> *(a + 7) = *(a + 7) + 1 ---> *(&a[0] + 7) = *(&a[0] + 7) + 1 --> *(1003 + 7) = *(1003 + 7) + 1
HATA a[8]++; ---> a[8] = a[8] + 1 ---> *(a + 8) = *(a + 8) + 1 ---> *(&a[0] + 8) = *(&a[0] + 8) + 1 --> *(1003 + 8) = *(1003 + 8) + 1
*(1011) = *(1011) + 1
*(1011) = ???1011 + 1
}
ASLINDA OLAN
for (int i = 0; i < len; i++) {
a[i]++; ---> a[i] = a[i] + 1 ---> *(a + i * KAP) = *(a + i * KAP) + 1 ---> *(&a[0] + i * KAP) = *(&a[0] + i * KAP) + 1 --> *(1003 + i * KAP) = *(1003 + i * KAP) + 1
a[0]++; ---> a[0] = a[0] + 1 ---> *(a + 0) = *(a + 0) + 1 ---> *(&a[0] + 0) = *(&a[0] + 0) + 1 --> *(1003 + 0) = *(1003 + 0) + 1
a[1]++; ---> a[1] = a[1] + 1 ---> *(a + 1 * 2) = *(a + 2) + 1 ---> *(&a[0] + 2) = *(&a[0] + 2) + 1 --> *(1003 + 2) = *(1003 + 2) + 1
*(1005) = *(1005) + 1
...
a[7]++; ---> a[7] = a[7] + 1 ---> *(a + 7) = *(a + 7) + 1 ---> *(&a[0] + 7) = *(&a[0] + 7) + 1 --> *(1003 + 7) = *(1003 + 7) + 1
HATA a[8]++; ---> a[8] = a[8] + 1 ---> *(a + 8) = *(a + 8) + 1 ---> *(&a[0] + 8) = *(&a[0] + 8) + 1 --> *(1003 + 8) = *(1003 + 8) + 1
*(1011) = *(1011) + 1
*(1011) = ???1011 + 1
}
}
task(a, 9); -> task(&a[0], 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment