Beginner C arrays and incrementation -
excuse amateurism i'm struggling understand basic incrementing mechanisms. comments correct?
#include <stdio.h> main() { int a[5]={1,2,3,4,5}; int i,j,m; = ++a[1]; // value of a[1] 3. i=3 j = ++a[1]; /* because of previous line a[1]=3 , a[1]=4? not in line defining i? */ m = a[i++]; /* retained value of 3 though value of a[1] has changed i++ incremented in printf()? */ printf("%d, %d, %d", i,j,m); }
i answering own question have fooled myself quite few times learning c far.
i = ++a[1]
increment value of a[1]
3
, result of ++a[1]
3
assigned i
.
j = ++a[1];
increment value of a[1]
4
, result of ++a[1]
4
assigned j
.
m = a[i++];
, assign value of a[3]
(as i
3 b now) m
4
, i
incremented 1
. i
becomes 4
.
Comments
Post a Comment