Last active
January 1, 2021 16:02
-
-
Save mrnirva/083df045d5e6c7508a03ba018aa61362 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Passing By Reference (Call by Reference) - Passing By Pointer (Call by Pointer) Örneği | |
// Parametrede sayı referansını oluşturup kullanıyoruz | |
void referanslaDegerDegistir(int &sayi){ | |
sayi = 10; // Sayının referansıyla yeni değer ataması yapıyoruz | |
} | |
// Parametrede pointer oluşturup kullanıyoruz | |
void pointerlaDegerDegistir(int *sayi2){ | |
*sayi2 = 10; // Sayıya bellekteki adresiyle ulaşarak yeni değer ataması yapıyoruz | |
} | |
int main(){ | |
int sayi = 5; // int tipinde normal bir sayı değişkeni oluşturuyoruz | |
int sayi2 = 5; // int tipinde normal bir sayı değişkeni oluşturuyoruz | |
referanslaDegerDegistir(sayi); // Sayının değerini değiştirmek için metoda yolluyoruz | |
pointerlaDegerDegistir(&sayi2); // Sayı 2'nin değerini pointerla değiştirmek için yolluyoruz | |
std::cout << sayi << endl; // Sayının son değerini yazdırıyoruz (10 Değerini Verecektir) | |
std::cout << sayi2 << endl; // Sayı 2'nin son değerini yazdırıyoruz (10 Değerini Verecektir) | |
// Her ikiside aynı performansa sahiptir | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment