Introduction to C

C LANGUAGE

Easy English Notes • Concepts • Programs • Output • Exam Tips

BEGINNER TO STRONG FOUNDATION

 

WHAT YOU WILL LEARN

PRACTICAL FOCUS

• History of C
• Features of C
• Installing C
• First C Program
• Compilation Process
• printf() and scanf()
• Variables
• Data Types
• Keywords
• Identifiers
• Operators
• Comments

• Easy explanations
• Real beginner examples
• Complete programs
• Expected output
• Common mistakes
• Easy tips
• Exam points
• Practice questions


 

1. History of C

C is a general-purpose programming language. It was developed by Dennis Ritchie at Bell Laboratories in the early 1970s. C became popular because it is fast, flexible and gives programmers good control over computer memory.

How C developed — in simple words

1.     Earlier languages such as BCPL and B influenced the design of C.

2.     Dennis Ritchie developed C at Bell Labs around 1972.

3.     C was used heavily in the development of the UNIX operating system.

4.     Because C was efficient and portable, it spread to many computers and operating systems.

5.     The language was later standardized so that programs could be written more consistently across systems.

Why should we learn C?

·        C teaches the basic ideas behind programming: variables, conditions, loops, functions, arrays and memory.

·        Many later languages were influenced by C syntax.

·        C is still used in operating systems, embedded systems, compilers and performance-sensitive software.

⭐ EASY TIP: Think of C as a language that teaches you what is happening inside the computer, not only how to get an answer.

 

📝 EXAM POINT: Dennis Ritchie is the key name to remember for the development of C.

 

2. Features of C

A feature is a useful quality of a programming language. C has many features that make it important even today.

Simple – The core language has a relatively small set of concepts and keywords.

Fast – C programs are compiled into efficient machine-level code.

Portable – The same source code can often be compiled on different systems with limited changes.

Structured – Large programs can be divided into functions and logical blocks.

Case-sensitive – age, Age and AGE are different identifiers.

Rich operators – C provides arithmetic, relational, logical, bitwise and assignment operators.

Pointers – C can work directly with memory addresses through pointers.

Extensible – Programmers can create functions and reusable modules.

Middle-level – C combines high-level programming features with low-level memory control.

⭐ EASY TIP: C is called a middle-level language because it supports both high-level programming and low-level operations.

 

3. How to Install C

To run a C program, you need a C compiler. GCC is one of the most commonly used C compilers.

Method 1: GCC on Windows

6.     Install a GCC toolchain such as MinGW-w64.

7.     After installation, make sure the compiler's bin folder is available in PATH.

8.     Open Command Prompt.

9.     Type the following command:

gcc --version

 

10.  If a GCC version appears, the compiler is ready.

Create and run your first file

hello.c

#include <stdio.h>

int main() {
    printf("Hello, C!");
    return 0;
}

 

Save the file as hello.c. Then compile it:

gcc hello.c -o hello

 

Run it. On Windows, the executable is normally hello.exe. On Linux/macOS, you can usually run:

./hello

 

OUTPUT
Hello, C!

 

⭐ EASY TIP: An IDE such as Code::Blocks or Visual Studio Code is an editor/development environment. The actual compilation is done by a compiler such as GCC.

 

4. First C Program

Let us understand the most common beginner program. Do not just memorize it—understand what each line does.

#include <stdio.h>

int main() {
    printf("Hello, World!");
    return 0;
}

 

Line-by-line explanation

#include <stdio.h> → Adds declarations for standard input/output functions such as printf().

int main() → Defines the main function. Program execution starts from main().

{ } → Marks the beginning and end of the function body.

printf("Hello, World!"); → Displays the message on the screen.

return 0; → Ends main and commonly indicates successful completion.

OUTPUT
Hello, World!

 

📝 EXAM POINT: A statement in C generally ends with a semicolon (;).

 

5. Compilation Process in C

The computer cannot directly execute normal C source code. The source code goes through several stages before an executable program is produced.

1. Source Code → The programmer writes a .c file.

2. Preprocessing → #include, #define and other preprocessor directives are handled.

3. Compilation → The C source is translated and checked for C language rules.

4. Assembly → Assembly instructions are converted into object/machine code.

5. Linking → Object code is combined with required library code to create an executable.

6. Execution → The operating system loads and runs the executable.

program.c
   ↓
Preprocessor
   ↓
Compiler
   ↓
Assembly
   ↓
Object Code
   ↓
Linker + Libraries
   ↓
Executable
   ↓
Run

 

Example GCC command

gcc program.c -o program

 

⭐ EASY TIP: If your program has a syntax error, compilation normally stops and the compiler reports the problem. Fix the error and compile again.

 

6. printf() and scanf()

These two functions are used in many beginner C programs. printf() is mainly used to display output, while scanf() is commonly used to read formatted input.

printf() — display output

int age = 20;
printf("Age = %d", age);

 

Important format specifiers

Specifier

Meaning

Example

%d

integer

printf("%d", age);

%f

floating-point value

printf("%.2f", price);

%c

single character

printf("%c", grade);

%s

string

printf("%s", name);

%lf

double with scanf()

scanf("%lf", &value);

scanf() — take input

int age;
printf("Enter age: ");
scanf("%d", &age);

 

The & before a normal variable gives its address. scanf() uses that address to store the input value.

Complete program

#include <stdio.h>

int main() {
    int age;
    float marks;
    char grade;

    printf("Enter age: ");
    scanf("%d", &age);

    printf("Enter marks: ");
    scanf("%f", &marks);

    printf("Enter grade: ");
    scanf(" %c", &grade);

    printf("\nAge = %d", age);
    printf("\nMarks = %.2f", marks);
    printf("\nGrade = %c", grade);

    return 0;
}

 

OUTPUT
Enter age: 21
Enter marks: 87.5
Enter grade: A

Age = 21
Marks = 87.50
Grade = A

 

⭐ EASY TIP: Notice the space before %c in scanf(" %c", &grade). It helps skip whitespace left in the input stream.

 

7. Variables in C

A variable is a named memory location used to store data. Its value can change while the program is running.

Basic syntax

data_type variable_name = value;

 

Examples

int age = 21;
float salary = 45000.50f;
char grade = 'A';

 

Three important words

Declaration – Telling C the variable's type and name.

Initialization – Giving a variable its first value when it is created.

Assignment – Giving or changing a value after declaration.

int marks;       // declaration
marks = 85;      // assignment

int age = 20;    // declaration + initialization

 

Rules for variable names

·        May contain letters, digits and underscore (_).

·        Must not begin with a digit.

·        Spaces are not allowed.

·        A keyword cannot be used as a variable name.

·        C is case-sensitive.

Program using variables

#include <stdio.h>

int main() {
    int quantity = 5;
    float price = 120.50f;
    float total = quantity * price;

    printf("Quantity = %d\n", quantity);
    printf("Price = %.2f\n", price);
    printf("Total = %.2f\n", total);

    return 0;
}

 

OUTPUT
Quantity = 5
Price = 120.50
Total = 602.50

 

8. Data Types in C

A data type tells C what kind of value a variable will store. It also affects the operations that can be performed and the amount of memory used.

Basic data types

Type

Stores

Example

Typical use

char

one character

char grade='A';

letters/symbols

int

whole number

int age=20;

count, age, marks

float

decimal value

float price=25.5f;

decimal values

double

more precision decimal

double pi=3.14159;

scientific/precise values

void

no value

void display(void);

functions with no return value

Derived and user-defined types

·        Array – stores multiple values of the same type.

·        Pointer – stores an address in memory.

·        Structure (struct) – groups related values of different types.

·        Union – different members share the same memory area.

·        Enumeration (enum) – creates named integer constants.

sizeof operator

#include <stdio.h>

int main() {
    printf("int = %zu bytes\n", sizeof(int));
    printf("char = %zu bytes\n", sizeof(char));
    printf("float = %zu bytes\n", sizeof(float));
    printf("double = %zu bytes\n", sizeof(double));
    return 0;
}

 

The exact size of some types can depend on the compiler and platform, so sizeof is the correct way to check the size on your system.

📝 EXAM POINT: Do not assume every C data type has exactly the same size on every computer.

 

9. Keywords in C

Keywords are reserved words that already have a special meaning in C. You cannot normally use a keyword as your variable or function name.

Common keywords

auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while

Program showing keywords

#include <stdio.h>

int main() {
    int age = 20;
    const int limit = 60;

    if (age < limit) {
        printf("Age is below the limit.");
    }

    return 0;
}

 

OUTPUT
Age is below the limit.

 

⭐ EASY TIP: If C gives a syntax error when you try to name a variable something like int or return, check whether you accidentally used a keyword.

 

10. C Identifiers

An identifier is a name created by the programmer. Examples include variable names, function names, array names and structure names.

Valid identifiers

·        studentName

·        total_marks

·        _count

·        marks1

·        calculateTotal

Invalid identifiers

·        2marks – starts with a digit

·        student name – contains a space

·        total-marks – contains hyphen

·        int – keyword

Program example

#include <stdio.h>

int main() {
    int studentAge = 21;
    float totalMarks = 456.5f;

    printf("Age = %d\n", studentAge);
    printf("Marks = %.2f\n", totalMarks);

    return 0;
}

 

OUTPUT
Age = 21
Marks = 456.50

 

⭐ EASY TIP: Use meaningful names. studentAge is much easier to understand than x.

 

11. C Operators

An operator is a symbol or keyword that tells C to perform an operation.

1. Arithmetic operators

Operator

Meaning

Example (a=10,b=3)

+

Addition

a + b = 13

-

Subtraction

a - b = 7

*

Multiplication

a * b = 30

/

Division

a / b = 3 (integer division)

%

Remainder

a % b = 1

2. Relational operators

These compare two values. In a condition, the result is treated as true or false.

==   equal to
!=   not equal to
>    greater than
<    less than
>=   greater than or equal to
<=   less than or equal to

 

3. Logical operators

&&   AND  → both conditions must be true
||   OR   → at least one condition is true
!    NOT  → reverses a condition

 

4. Assignment operators

=    +=    -=    *=    /=    %=

 

5. Increment and decrement

x++;   // increase by 1
x--;   // decrease by 1

 

6. Bitwise operators

&    AND
|    OR
^    XOR
~    NOT
<<   left shift
>>   right shift

 

Bitwise operators work on the individual bits of integer values.

7. Conditional operator

condition ? value_if_true : value_if_false;

 

8. sizeof

sizeof(variable_or_type)

 

Complete operator program

#include <stdio.h>

int main() {
    int a = 10, b = 3;

    printf("Addition = %d\n", a + b);
    printf("Subtraction = %d\n", a - b);
    printf("Multiplication = %d\n", a * b);
    printf("Division = %d\n", a / b);
    printf("Remainder = %d\n", a % b);

    if (a > b && b > 0) {
        printf("Both conditions are true.\n");
    }

    return 0;
}

 

OUTPUT
Addition = 13
Subtraction = 7
Multiplication = 30
Division = 3
Remainder = 1
Both conditions are true.

 

⭐ EASY TIP: The = operator assigns a value. The == operator compares two values. This is one of the most common beginner mistakes.

 

12. Comments in C

Comments are notes written in source code for humans. The compiler does not treat them as executable program instructions.

Single-line comment

// This is a single-line comment
int age = 20; // stores the age

 

Multi-line comment

/*
   This is a multi-line comment.
   It can contain several lines.
*/

 

Program with comments

#include <stdio.h>

int main() {
    // Store two numbers
    int a = 10;
    int b = 20;

    /* Add the numbers
       and display the result */
    int sum = a + b;

    printf("Sum = %d", sum);

    return 0;
}

 

OUTPUT
Sum = 30

 

⭐ EASY TIP: Use comments to explain why something is being done, especially when the logic is not obvious.

 


 

One-Page Quick Revision

TERM

EASY MEANING

C

General-purpose, compiled programming language.

Developer

Dennis Ritchie, Bell Labs, early 1970s.

main()

Usual starting function of a C program.

printf()

Used for formatted output.

scanf()

Commonly used for formatted input.

Variable

Named memory location used to store a value.

Data type

Describes the kind of data a variable stores.

Keyword

Reserved word with a special meaning in C.

Identifier

Programmer-defined name.

Operator

Performs an operation on operands.

Comment

Human-readable note ignored as program instructions.

Compiler

Translates C source into lower-level code/executable form.

Practice Questions

11.  What is C? Who developed it?

12.  Explain any five features of C.

13.  What is a compiler? Why do we need it?

14.  Write a C program to print Hello, World! and explain each line.

15.  Explain the stages of the C compilation process.

16.  What is the difference between printf() and scanf()?

17.  What is a variable? Explain declaration, initialization and assignment.

18.  Explain int, char, float and double with examples.

19.  What are keywords? Give examples.

20.  What are identifiers? Write rules for naming them.

21.  Explain arithmetic, relational, logical and assignment operators.

22.  What are comments? Explain single-line and multi-line comments.

Final beginner advice

Do not try to memorize every program. First understand the pattern: include the required header, start main(), declare variables, take input if needed, process the data, display the result, and return from main(). Then practise by changing the values and messages yourself.

⭐ EASY TIP: Best way to learn C: READ → TYPE THE PROGRAM YOURSELF → RUN → SEE THE OUTPUT → CHANGE ONE LINE → RUN AGAIN.

 

Scroll to Top