C Programming: Memory, Pointers and the Stack ยท C Basics
Integer division, the remainder, casting to get decimals, and the difference between x++ and ++x.
#include <stdio.h>
int main(void) {
int a = 17, b = 5;
int quotient = a / b; /* integer division drops the remainder */
int remainder = a % b;
double exact = (double)a / b; /* cast first to get a decimal answer */
int x = 5;
int post = x++; /* uses 5, then x becomes 6 */
int pre = ++x; /* x becomes 7, then uses 7 */
int both = (a > 10) && (b > 10);
printf("%d %d %.1f %d %d %d\n", quotient, remainder, exact, post, pre, both);
return 0;
}a is created on the stack with the value 17. b is created on the stack with the value 5.x is created on the stack with the value 5.3 2 3.4 5 7 0.0.