C/C++ Arena

Step 6 of 6

Constants and sizeof

Put const in front of a declaration to make a variable read-only. Trying to change it later is a compile error, which protects you from accidents.

const int MAX_PLAYERS = 10;

sizeof tells you how many bytes a type uses. On this site (and most machines) int is 4 bytes, double is 8 and char is always 1. Print a size with %zu.

Your turn: declare a constant int named ROUND_TIME equal to 115, and print:

Round time: 115
int bytes: 4

Previous: Characters with char