Ad space (banner)
๐Ÿ”งC Lessons
Lesson 3 / 68

Working with Variables

This lesson covers the basics of using variables in C, so you understand explicit, typed variable declarations. It's for anyone searching "C variable tutorial."

A variable is like a "labeled box" that holds a value under a name. Declare one with type variableName = value;. A string is handled as an array of char.

The example declares two variables, char name[] = "Alice" and int age = 14, and builds a message using format specifiers in printf("...%s...%d...", name, age). %s represents a string, and %d represents an integer.

A common early mistake is not realizing C has no dedicated string type โ€” strings are handled as an array of characters. Since you don't get the convenient string manipulation many other languages offer, you need a deeper understanding of how memory works.

In real projects, staying conscious of a variable's type and the memory size it reserves is the foundation of writing C programs.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)