/* * demonstrates the use of ++, -- * * Matt Bishop, ECS 36A * * April 22, 2024 * first version */ #include <stdio.h> /* * the program itself */ int main(void) { int m; /* integer that is incremented or decremented */ int p; /* used to hold vaue before or after m is altered */ /* ++var */ m = 7; printf("m = %d before; ", m); p = ++m; printf("p = ++m; p = %d, m = %d\n", p, m); /* var++ */ m = 7; printf("m = %d before; ", m); p = m++; printf("p = m++; p = %d, m = %d\n", p, m); /* --var */ m = 7; printf("m = %d before; ", m); p = --m; printf("p = --m; p = %d, m = %d\n", p, m); /* var-- */ m = 7; printf("m = %d before; ", m); p = m--; printf("p = m--; p = %d, m = %d\n", p, m); /* all done! */ return(0); }
|
ECS 36A, Programming & Problem Solving Version of April 2, 2024 at 12:13PM
|
You can get the raw source code here. |