█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/Programming Languages/C/C Fundamentals
45 minBeginner

C Fundamentals

After this lesson, you will be able to: Use C's data types, operators, control flow, functions, and main signature.

Basic syntax. C is small; the danger is in details.

Prerequisites:C Setup

Types + operators + control flow

Read each line.

tsx
#include <stdio.h>
#include <stdbool.h>
int main(void) {
// Primitive types, sizes are platform-dependent, EXCEPT stdint.h
int n = 42; // typically 32-bit
long ln = 100000L; // at least 32-bit
long long lln = 999LL; // at least 64-bit
float f = 3.14f;
double d = 3.14159;
char c = 'A'; // 1 byte; really a small int
bool b = true; // from stdbool.h
// Use stdint.h for portable widths
// int32_t, int64_t, uint8_t, uint64_t, exact sizes
// Operators
int sum = n + 8;
int rem = n % 5;
int isEven = (n % 2 == 0);
// Control flow
if (n > 0) printf("pos\n");
else if (n == 0) printf("zero\n");
else printf("neg\n");
for (int i = 0; i < 5; i++) printf("%d\n", i);
int j = 0;
while (j < 5) { printf("%d\n", j); j++; }
switch (n) {
case 0: printf("zero\n"); break;
case 42: printf("answer\n"); break;
default: printf("other\n");
}
return 0;
}

Functions + main signatures

Declare before use; main can take args.

tsx
#include <stdio.h>
// Forward declaration
int add(int a, int b);
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "usage: %s <name>\n", argv[0]);
return 1;
}
printf("Hello, %s\n", argv[1]);
printf("2 + 3 = %d\n", add(2, 3));
return 0;
}
int add(int a, int b) {
return a + b;
}

printf format specifiers

%d / %i, int. %u, unsigned. %ld, long. %lld, long long. %f, float/double. %.2f, 2 decimals. %c, char. %s, string. %p, pointer. %x, hex. %%, literal percent. Mismatched format + type is undefined behavior. Always match: `printf("%d\n", 3.14)` is wrong.

Common mistakes only experienced C devs avoid

Using `int` for sizes (use `size_t`). Mismatched printf format and type. Integer overflow without thinking. INT_MAX + 1 is undefined behavior in C. Forgetting `void main()` is non-standard. Use `int main(void)` or `int main(int argc, char *argv[])`.

Quick Check

What's wrong with `printf("%d\n", 3.14);`?

Pick the bug.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←C Dev Environment Setup
Back to C
Arrays and Strings→