Uczę się programowania i zacząłem od języka C. Czytałem książkę Let the C. I przeglądałem ten program w tej książce.Pre inkrement a Post przyrost w tablicy
main()
{
int a[5] = { 5, 1, 15, 20, 25 } ;
int i, j, k = 1, m ;
i = ++a[1] ;
j = a[1]++ ;
m = a[i++] ;
printf ("\n%d %d %d", i, j, m) ;
}
Moje zrozumienie było, to wydrukować i as 2
, j as 1
i m as 15
Ale jakoś drukuje jak i as 3
, j as 2
i m as 15
? Dlaczego tak jest?
Poniżej jest moje understanding-
b = x++;
In this example suppose the value of variable ‘x’ is 5 then value of variable ‘b’ will be 5 because old value of ‘x’ is used.
b = ++y;
In this example suppose the value of variable ‘y’ is 5 then value of variable ‘b’ will be 6 because the value of ‘y’ gets modified before using it in a expression.
Czy jest coś złego w moim zrozumieniu?
nie jestem pewien, że zaczynają uczyć się programowania w C jest najlepszym sposobem. Czy rozważałeś rozpoczęcie pracy ze Scheme i czytanie [SICP] (http://mitpress.mit.edu/sicp/) (lub może zaczynając od Ocaml, czy może Python)? –