C Programming: Memory, Pointers and the Stack ยท Structs and Types
Constants with const, and text-replacing macros with #define, including why macro arguments need brackets.
#include <stdio.h>
#define SQUARE(x) ((x) * (x))
#define MAX_USERS 3
int main(void) {
const double PI = 3.14159; /* the compiler refuses any change to PI */
int users[MAX_USERS] = {0};
int s = SQUARE(4);
int tricky = SQUARE(1 + 2); /* thanks to the brackets: 9, not 5 */
double area = PI * SQUARE(2);
users[MAX_USERS - 1] = s;
printf("%d %d %.2f %d\n", s, tricky, area, users[2]);
return 0;
}users is created on the stack with the value [0, 0, 0].area is created on the stack with the value 12.5664.users changes from [0, 0, 0] to [0, 0, 16].16 9 12.57 16.0.