Ch 3 · Variables & Data Types · C

Topic 3 of 13 in C — Complete Tutorial (Beginner) — 2 lessons.

Variables and Types

A variable is a named box in memory that stores a value. In C, you must declare a variable's type before using it — the type tells C how much memory to set aside and what kind of value the box holds. The most common types are int (whole numbers), float and double (decimals), and char (a single character). You write the type, the name, then optionally = and a starting value.

Constants with const and #define

Sometimes a value should never change — like the number of days in a week, or the value of PI. C gives you two ways to make a constant. The const keyword in front of a variable locks its value so it cannot be reassigned. The #define directive at the top of the file creates a named replacement the compiler substitutes everywhere. Both make code safer and easier to read by giving fixed numbers meaningful names.

All topics in C Beginner

  1. Introduction to Programming & C
  2. Your First C Program
  3. Variables & Data Types
  4. Input & Output
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Functions
  9. Arrays
  10. Strings
  11. Pointers
  12. Structures
  13. Mini-Projects & Practice