C Language Basics
Variables, data types, operators, expressions, input/output functions, and control flow in C.
What You Will Learn in C Language Basics
C is a procedural, middle-level language with manual memory management that compiles to efficient machine code, widely used in systems programming and embedded systems.
- C program structure: includes → main function → statements; compiled with `gcc filename.c -o output`.
- Data types: int (4B), float (4B), double (8B), char (1B). Use `sizeof()` to check.
- Format specifiers: `%d` int, `%f` float, `%lf` double, `%c` char, `%s` string.
- `scanf()` reads input; `printf()` outputs; `&variable` passes address for scanf.
- Operators: arithmetic (+,-,*,/,%), relational (==,!=,<,>), logical (&&,||,!), bitwise.
- Constants with `#define` or `const`; global variables vs local variables scope.
Syntax
#include <stdio.h>
int main() {
// variable declarations
int x;
float y;
char ch;
// input
scanf("%d %f %c", &x, &y, &ch);
// output
printf("x=%d, y=%.2f, ch=%c\n", x, y, ch);
return 0;
}Complete Code Example
#include <stdio.h>
int main() {
int a = 10, b = 3;
printf("Sum: %d\n", a + b); // 13
printf("Division: %.2f\n", (float)a/b); // 3.33
printf("Modulus: %d\n", a % b); // 1
// Ternary operator
int max = (a > b) ? a : b;
printf("Max: %d\n", max); // 10
// Swap using XOR
a ^= b; b ^= a; a ^= b;
printf("After swap: a=%d, b=%d\n", a, b); // a=3, b=10
return 0;
}Example
`printf("%d", 10/3)` outputs `3` because integer division truncates the decimal.
Expected Exam Questions — C Language Basics
Q1.What is the difference between `printf` and `scanf`?
Q2.What is the difference between `int` and `float` in C?
Q3.What is the purpose of `#include` and `#define`?
🔘 MCQ Practice — C Language Basics
MCQ 1.What is the output of `printf("%d", 5/2)` in C?
✓ Correct Answer: 2
MCQ 2.Which header file contains `scanf()` and `printf()` in C?
✓ Correct Answer: stdio.h
Download C Language Basics PDF Notes
Get the complete C Language Basics notes as a PDF — free for enrolled students, or browse our public study materials library.