Skip to content
Learn Netverks

Lesson

Step 7/36 19% through track

variables-types

Variables and types

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Variables and types: the syntax, patterns, and safety habits you need before advancing in C.

Teams still ship Variables and types in C codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Variables and types in contexts like: Kernels, drivers, embedded devices, and performance libraries used by other languages.

Write C in main.c with int main(), click Run on server—the dev runner compiles with cc/gcc -std=c11 and runs the binary; read stderr for compile and linker errors (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

C variables have an explicit type declared before the name: int count = 0;. Unlike JavaScript, you cannot silently change a variable from int to char * without a compile error.

Common scalar types

  • int, long — integers (width is platform-defined; use <stdint.h> for fixed sizes)
  • double, float — floating point (prefer double for precision)
  • char — single byte character; also used in strings
  • _Bool or bool with stdbool.h — true/false

Declaration and initialization

int age = 30;
double pi = 3.14159;
char letter = 'A';

Uninitialized local variables contain indeterminate values—always initialize before use.

Important interview questions and answers

  1. Q: Size of int?
    A: At least 16 bits per standard; typically 32 bits on modern desktops—use int32_t when width matters.
  2. Q: char signed or unsigned?
    A: Implementation-defined; use signed char or unsigned char explicitly when it matters.

Self-check

  1. Why initialize local variables?
  2. Which header provides fixed-width integers like int32_t?

Interview prep

Why initialize locals?

Reading uninitialized automatic variables is undefined behavior—the value is indeterminate.

When use stdint.h?

When exact bit widths matter—embedded systems, network protocols, and cross-platform binary formats.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • int size portable?
  • unsigned when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump