C/C++ C++ kodunda hata nerede?

Peki mesela
Given the following program:

int main() {
int a = 1;
cout << ++a + a++ << endl;
cout << a << endl;
}
Predict the output of the program and explain the result.
Burda ne yapmak lazım?
 
Peki mesela
Given the following program:

int main() {
int a = 1;
cout << ++a + a++ << endl;
cout << a << endl;
}
Predict the output of the program and explain the result.
Burda ne yapmak lazım?
Sırayla gidersek cout << ++a + a++ << endl; ifadesi için
++a demiş, bu kısım 2 eder.
Daha sonra + a++, burada da 2 eder. 1. çıktı 4 verir.

Ama cout < a << endl;
için yukarıda işlemlerde bulunan + a++ sonradan ekleme olduğu için a = 3 olur ve çıktı olara 3 verir.
 
Bu siteyi kullanmak için çerezler gereklidir. Siteyi kullanmaya devam etmek için çerezleri kabul etmelisiniz. Daha Fazlasını Öğren.…