Back to C Programming
🖨️C Programming

C Language Basics

Variables, data types, operators, expressions, input/output functions, and control flow in C.

BeginnerIntermediateAdvanced

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`?
Answer: `printf(format, args)` writes formatted output to stdout. `scanf(format, &args)` reads formatted input from stdin — note the `&` (address-of) operator is required for variables so scanf can write to them.
Q2.What is the difference between `int` and `float` in C?
Answer: `int` stores whole numbers (no decimal), typically 4 bytes. `float` stores single-precision decimal numbers (4 bytes, ~7 decimal digits precision). `double` is double-precision (8 bytes, ~15 digits). Use `%d` for int, `%f` for float, `%lf` for double.
Q3.What is the purpose of `#include` and `#define`?
Answer: `#include <header.h>` includes standard library headers (preprocessor directive). `#define PI 3.14159` defines a macro constant — text substitution before compilation. Unlike variables, macros have no type and no memory.

🔘 MCQ Practice — C Language Basics

MCQ 1.What is the output of `printf("%d", 5/2)` in C?
A. 2.5
B. 2
C. 3
D. Compile error

✓ Correct Answer: 2

MCQ 2.Which header file contains `scanf()` and `printf()` in C?
A. stdlib.h
B. string.h
C. math.h
D. stdio.h

✓ 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.

More C Programming Topics

Related Subjects

Frequently Asked Questions — C Language Basics

What is C Language Basics in C Programming?
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.
What is the difference between `printf` and `scanf`?
`printf(format, args)` writes formatted output to stdout. `scanf(format, &args)` reads formatted input from stdin — note the `&` (address-of) operator is required for variables so scanf can write to them.
What is the difference between `int` and `float` in C?
`int` stores whole numbers (no decimal), typically 4 bytes. `float` stores single-precision decimal numbers (4 bytes, ~7 decimal digits precision). `double` is double-precision (8 bytes, ~15 digits). Use `%d` for int, `%f` for float, `%lf` for double.
What is the purpose of `#include` and `#define`?
`#include <header.h>` includes standard library headers (preprocessor directive). `#define PI 3.14159` defines a macro constant — text substitution before compilation. Unlike variables, macros have no type and no memory.
How do I prepare C Language Basics for exams?
To master C Language Basics, start by reading the theory carefully, then go through solved examples step by step. Practice numericals (if applicable), revise key formulas, and attempt previous year questions. SII notes cover all these aspects in a structured manner.
Are these C Language Basics notes free?
Yes! SII provides free access to C Language Basics notes and introductory study materials. Enrolled students get full access to detailed notes, solved papers, and live doubt-clearing sessions.
Which exams ask questions from C Language Basics?
C Language Basics is an important topic tested in Beginner, Intermediate, Advanced board exams, as well as University Semester Exams. It frequently appears in both short-answer and long-answer sections.