Placement Prep

Variables and Keywords in C: A Complete Reference

Learn the rules for naming variables in C, all 32 reserved keywords by category, storage classes, scope, and the interview traps that trip up placement candidates.

By FACE Prep Team 6 min read
c-programming variables-in-c c-keywords placement-prep technical-interview

Variables in C are named memory locations; knowing their rules plus all 32 reserved keywords is the baseline for any C technical interview.

When your program runs, the operating system allocates memory for it. Without named variables, every read and write would reference raw addresses like 0xBFFF1A28. That becomes unmanageable in a program of even moderate size. Variables give those addresses human-readable labels and bind a data type to them, so the compiler knows how many bytes to reserve and how to interpret the bits.

What a Variable Is in C

A variable has four properties: a name (identifier), a data type, a value, and an address in memory. The C identifier rules specify exactly what names are legal.

Naming Rules

RuleValid ExampleInvalid Example
Must start with a letter or `_`count, _total2count, 99names
Subsequent characters: letters, digits, `_` onlyitem_2, maxValmy-count, item@2
Case-sensitiveCount and count are different
Cannot be a C keywordmyInt, floatValint, float
No spaces or special characterspage_countpage count
First 63 characters significant (C99+)Keep names under 63 chars

A name like 2count fails because it starts with a digit. A name like my-count fails because - is the subtraction operator in C, not a naming character. These exact cases appear in campus aptitude MCQs across companies that test C fundamentals.

One distinction worth remembering: C is fully case-sensitive. Count, count, and COUNT are three separate identifiers. None of them is a keyword. Only case in lowercase is reserved.

Declaring and Initializing Variables

Declaration tells the compiler to reserve memory for a variable of a given type. Initialization assigns a starting value at the same time.

int age;          /* declaration only — value is undefined */
int age = 21;     /* declaration + initialization */
float gpa = 8.5;
char grade = 'A';

You can declare multiple variables of the same type in one statement:

int a, b, c;            /* three separate variables, all uninitialized */
int x = 1, y = 2, z = 3;  /* three initialized variables */

int a, b, c; does not make b and c aliases of a. They are independent memory locations. Modifying a has no effect on b or c.

Core Data Types

TypeTypical SizeNotes
char1 byteHolds a single character or small integer
int4 bytesDefault integer type
short2 bytesSmaller integer range
long4 or 8 bytesPlatform-dependent
float4 bytesSingle-precision floating point
double8 bytesDouble-precision floating point
unsigned int4 bytesNon-negative integers only

Sizes are implementation-defined: the C standard sets minimums, not exact sizes. Most placement MCQs assume a 32-bit or 64-bit Linux/Windows platform, where the values above apply.

For the mistakes that get C programs rejected in interviews before they even compile, the common errors in C programming guide covers the patterns that appear most often.

Scope and Storage Classes

Scope determines where a variable is visible. Storage class determines its lifetime and where it lives in memory. Both concepts appear in technical rounds.

Local and Global Scope

A local variable is declared inside a function or block { }. Only code within that block can see it.

void greet() {
    int x = 10;  /* x is local to greet() */
    printf("%d\n", x);
}
/* x does not exist here — accessing it is a compile error */

A global variable is declared outside all functions. Every function in the file can read and modify it. Global variables that are not explicitly initialized default to zero.

int count = 0;   /* global — visible to all functions below */

void increment() {
    count++;     /* valid */
}

Storage Classes

C has four storage-class keywords. They control lifetime, default values, and where in memory a variable lives.

KeywordScopeLifetimeDefault Value
autoBlockDuration of the enclosing function callUndefined (garbage)
registerBlockDuration of the enclosing function callUndefined (garbage)
staticBlock or fileEntire program executionZero
externFile or programEntire program executionZero

Key facts for placement tests:

  • auto is the default for local variables. You almost never write it explicitly — the compiler assumes it.
  • register is a hint to use a CPU register for faster access. Modern compilers may ignore it. You cannot take the address of a register variable with &.
  • static inside a function means the variable keeps its value between calls:
void counter() {
    static int calls = 0;   /* initialized once; retains value */
    calls++;
    printf("Called %d times\n", calls);
}

Call counter() three times and it prints 1, 2, then 3. A non-static local would print 1 every time because it reinitializes on each call.

  • extern declares that a variable is defined in another source file. It does not allocate new memory — it tells the compiler to find the definition elsewhere at link time.

Understanding scope is a prerequisite before moving to pointers and arrays in C, where scope rules intersect with pointer lifetime and produce subtle bugs.

All 32 Keywords in C

The C89/C90 standard defines 32 reserved words. None can be used as an identifier. Attempt it and the compiler errors immediately. The cppreference keyword list documents every keyword along with the standard version it was introduced in.

CategoryKeywords
Data typeschar, int, float, double, long, short, signed, unsigned, void
Storage classauto, register, static, extern
Control flowif, else, switch, case, default, break, continue, return, goto
Loopsfor, while, do
Derived typesstruct, union, enum, typedef
Modifiersconst, volatile, sizeof
  • Data types: 9
  • Storage class: 4
  • Control flow: 9
  • Loops: 3
  • Derived types: 4
  • Modifiers: 3
  • Total: 32

All 32 are lowercase. INT, FLOAT, IF are valid identifiers (though confusing in practice). int, float, if are keywords.

C99 added five more keywords: _Bool, _Complex, _Imaginary, inline, restrict. C11 added _Alignas, _Alignof, _Atomic, _Generic, _Noreturn, _Static_assert, _Thread_local. Campus placement tests almost always ask about the original 32, so that is the count to memorise.

Interview Traps: Variables and Keywords

These are the question types that recur in technical screening rounds at product and service companies alike.

Trap 1: Keyword as Identifier

int int = 5;   /* compile error — int is a keyword */
int Int = 5;   /* valid — Int is not a keyword */
int INT = 5;   /* valid — INT is not a keyword */

Most candidates know you cannot use keywords as names, but forget that C’s case-sensitivity means only the exact lowercase spelling is reserved. Int, INT, and iNT are all legal identifiers.

Trap 2: Uninitialized Local Variable

int x;
printf("%d", x);   /* undefined behavior — not zero */

Local variables do not default to zero. The value is whatever happened to be in that memory address before the function ran, commonly called a garbage value. Global variables and static locals default to zero. This distinction appears in MCQ form in almost every campus written test.

Trap 3: Multi-Variable Initialization Syntax

int a = b = c = 0;    /* compile error — b and c undeclared */
int a = 0, b = 0, c = 0;  /* correct */

The chained-assignment form works after all three variables are declared, but not inside the declaration itself.

Trap 4: Names Starting with `_`

A name starting with `_` followed by an uppercase letter (like _INT) or a second `_` (like __count) is reserved for the C implementation, meaning the compiler and standard library. Technically these names compile, but they can clash with compiler-internal symbols and produce unpredictable behavior. Placement MCQs sometimes ask whether such names are “valid.” The correct answer is: syntactically valid but reserved for the implementation.

For a structured walkthrough of the question patterns you will face, the C programming interview questions guide covers 31 patterns with full programs.

Reinforcing the Rules Through Practice

The 32 keywords and identifier rules are the kind of material that fades without active recall. Reading the table is a start. Writing programs that trigger the exact compile errors described above makes them stick.

TinkerLLM gives you a way to do that without any local compiler setup. Paste the static counter above, ask why removing static changes the output, then paste the int int = 5; trap and ask what error the compiler will report. At ₹299 you get real LLM API calls that respond to specific C snippets rather than generic explanations. The 32-keyword table and the storage-class rules from this article become reference material you test against a live session rather than facts you passively re-read.

Primary sources

Frequently asked questions

What are all 32 keywords in C?

The 32 C89 keywords are: auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while.

Can I use a keyword as a variable name in C?

No. Keywords are reserved by the compiler. Using int or if as a variable name causes a compilation error immediately.

What is the difference between variable declaration and initialization?

Declaration reserves memory for a variable, for example int x; with no starting value assigned. Initialization assigns a value at declaration time, for example int x = 0.

What is the default value of an uninitialized local variable?

Undefined behavior: the value is whatever was left in that memory location, commonly called a garbage value. Global and static variables default to zero automatically.

Which storage class is the default for local variables?

auto is the default storage class for local variables. You rarely write it explicitly because the compiler assumes it.

Are C keywords case-sensitive?

Yes. int is a keyword, but Int or INT are not. C is fully case-sensitive, so identifiers that differ only in case are distinct.

How many characters of a variable name are significant in C?

The C99 standard guarantees that at least the first 63 characters of an internal identifier are significant. The older C89 standard guaranteed only 31 characters.

Build AI projects

A self-paced playground for building with LLMs.

TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.

Try TinkerLLM (₹299 launch)
Free AI Roadmap PDF