Skip to content
CurriculumChapter 02 ยท Foundations
BeginnerHigh focus~14 min

Data Types, Constants & Qualifiers

A type tells the compiler how many bytes to reserve and how to interpret the bit pattern. Qualifiers adjust range and signedness.

In plain English

A data type is the size of the box and the shape of what goes inside it.

01

Core types and qualifiers

The core types are int for whole numbers, float and double for real numbers, and char for a single character or small integer. Qualifiers refine them: short and long change the range, while signed and unsigned change how the bits are interpreted. sizeof reports the number of bytes a type or expression occupies, so use it instead of assuming a size.

chapter-02.cC
printf("char   = %zu byte\n", sizeof(char));
printf("int    = %zu bytes\n", sizeof(int));
printf("double = %zu bytes\n", sizeof(double));
02

Constants and escape sequences

A literal constant has a type: 42 is an int, 42.0 is a double, 19.95f is a float, and 'A' is a char. The suffix matters: without f, a floating literal is a double. Escape sequences write characters that are hard to type or invisible. The full common set is \a (alert), \b (backspace), \f (form feed), \n (newline), \r (carriage return), \t (horizontal tab), \v (vertical tab), \\ (backslash), \' (single quote), \" (double quote), and \? (question mark). Octal and hexadecimal escapes such as \101 and \x41 also produce a character. A symbolic constant created with #define or const gives a value a name.

chapter-02.cC
#define MAX_USERS 100
const double PI = 3.141592653589793;

float price = 19.95f;   /* float constant suffix */
double exact = 19.95;   /* double constant */

printf("alert=\a backspace=\b formfeed=\f newline=\n");
printf("carriage=\r tab=\t vertical=\v backslash=\\ quote=\"\n");
printf("octal A=\101 hex A=\x41\n");

Key takeaways

  • int, float, double, and char are the core types.
  • short/long change range; signed/unsigned change interpretation.
  • sizeof is an operator that reports byte size.
  • The f suffix makes a floating literal float; without it the literal is double.
  • Escape sequences represent single special characters, including invisible control characters.

Common pitfalls

  • Assuming int is always four bytes.
  • Mixing signed and unsigned values in comparisons.
  • Forgetting that a char literal uses single quotes.
  • Writing 19.95f when you meant a double, or 19.95 when you meant a float.

Key focus

  • Expect sizeof and type-range questions.
  • Know the full escape table, not just newline and tab.
  • Remember the f suffix when a question distinguishes float from double constants.

Quick check

0 / 3 answered

1. Which operator reports the size of a type or expression in bytes?

2. Which escape sequence represents the null character?

3. Which literal is a float constant?