GCGY Beta v1.0.1
GrowCodeEngineering
← Back to Hub
Back to Topics
c / c-fundamentals
15 mins

C Level 1: Data Types, printf, and scanf

Why This Matters: C requires static type declarations so the compiler knows the exact byte size to allocate in physical RAM.
## Statically Typed Memory in C

Every variable in C must be declared with its **type** so the memory allocation size is fixed at compile time.

### Core Data Types & Sizes
- `int`: 4 bytes (-2,147,483,648 to 2,147,483,647) — Format: `%d`
- `float`: 4 bytes single-precision float — Format: `%f`
- `double`: 8 bytes double-precision float — Format: `%lf`
- `char`: 1 byte ASCII character — Format: `%c`
MENTAL MODEL & MEMORY LAYOUT
RAM Memory Layout:
┌──────────────────┬──────────────────┐
│ Address 0x1000   │ int age (4 B)    │ => 20
├──────────────────┼──────────────────┤
│ Address 0x1004   │ float gpa (4 B)  │ => 3.92
└──────────────────┴──────────────────┘
COMMON PITFALLS TO AVOID
  • Using wrong format specifier (e.g. %d for float instead of %f).
  • Forgetting the address-of operator `&` in scanf(`%d`, &num).
Reading User Input with scanf
#include <stdio.h>

int main() {
    int num;
    printf("Enter integer: ");
    scanf("%d", &num); // '&' passes memory address
    printf("You entered: %d\n", num);
    return 0;
}

scanf requires the memory address (&num) so it can write directly into the variable's RAM location.

CONCEPT MASTERY CHECKPOINT

Why must you pass `&num` instead of `num` to scanf()?

NEXT RECOMMENDED LESSON
C Level 2: Control Flow & Loops
Continue Path
Challenge: Complete the C code to multiply two integers `a = 6` and `b = 7` and print the result using printf.
C Level 1: Data Types, printf, and scanf
1
2
3
4
5
6
7
8
9
10
11
12
13
No test case execution results available yet. Click "Run Code" to evaluate your solution.