UMBC CS 104
UMBC CMSC 104 * CSEE | 104 | current 104

CMSC 104, Section 105

Increment ++ and Decrement -- Problems


What do the following c programs output: #include <stdio.h> main() { int n = 0; while ( ++n < 11 ) { printf("\t %2d \t %5d \t %5d \t %6d \n",n,10 * n,100 * n,1000 * n); } return 0; }
#include <stdio.h> main() { int c; c = 5; printf(" %d \n " , c); printf(" %d \n " , --c); printf(" %d \n \n " , c); c = 5; printf(" %d \n " , c); printf(" %d \n " , c--); printf(" %d \n \n " , c); c = 5; printf(" %d \n " , c); printf(" %d \n " , c++); printf(" %d \n " , ++c); printf(" %d \n \n" , c); return 0; }
#include <stdio.h> main() { int i = 0; while ( ++i < 11 ) { printf( "%d " , i ); } return 0; }
#include <stdio.h> main() { int i = 0; while ( i++ < 11 ) { printf( "%d " , i ); } return 0; }