Instruction

Last Updated : Jan 2026


Instruction is a statement that tells the computer what to do.So we start with Data Types,because if you remember the previous lesson, identifiers are used to store data.

Data Types

The type of data that is stored in an identifier is called its data type.These are following Types:

C Data Types
│
├── Basic / Primary
│   ├── int
│   ├── float
│   ├── double
│   ├── _Bool
│   └── char
│
├── Derived
│   ├── Array
│   ├── Pointer
│   └── Function
│
├── User-defined / Other
|   ├── struct
|   ├── union
|   └── enum
│
└── void

Basic/Primary Data Types

A data type i.e built in data type provides by the C compiler.Each Data have limited sized and range of values which is vary depending on the system architecture i.e 32 bit or 64 bit.

int

A integer is a number without a fractional part.

KeywordSizeRangeFormat Specifier
int4 bytes-2147483648 to 2147483647%d or %i

Let understand the above table:

  • Keyword: int (use to make integer variable)
  • Size: 4 bytes
    • Range: (8×4=32bitsi.e232=4,294,967,296)(8\times4 = 32 bits\quad i.e \quad2^{32} = 4,294,967,296)
    • min-value: −(232−1)=−2,147,483,648-(2^{32-1}) = -2,147,483,648
    • max-value: (232−1)−1=2,147,483,647(2^{32-1})-1 = 2,147,483,647
  • Format Specifier: %d or %i
    • It is used to print integer value

Note : You can check the size and range of any data type by using sizeof() function.We can use Type Modifier to change the size of a data type.

Type Modifiers

  • short (2 bytes)
  • long (4 bytes)
  • long long int (8 bytes)
  • unsigned int (4 bytes, positive only)
  • signed int (4 bytes , positive and negative i.e default setting)

Note : Each modifier has its own format specifier.

Format Specifiers

SpecifierData TypeDescriptionExample
%d / %iintSigned decimal integerint age = 20;
%uunsigned intUnsigned decimal integerunsigned int age = 20;
%ldlong intLong decimal integerlong int age = 20;
%lldlong long intLong long decimal integerlong long int age = 20;
%ooctal valueOctal integer20 i.e 0o24;
%x / %Xhexadecimal valueUnsigned Hexadecimal integer(lowercase/uppercase)15 i.e 0xF;
%bbinary valueBinary integer15 i.e 0b1111;

Till Know,we know everything to start our first C program.

C Program Structure

#include <stdio.h>

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

We'll understand how this program is structured. The goal is not memorizing the template. The goal is understanding why each part exists.

Every can divide it into:

#include <stdio.h>
        ↓
Preprocessor instruction

int main()
        ↓
Main function

{
        ↓
Beginning of block

printf(...)
        ↓
Statement

return 0;
        ↓
Return statement

}
        ↓
End of block

So a C program is not one single thing. It is made from several components.

Header Files

A header file normally contains declarations and other information that can be shared between source files.

Look at:

#include <stdio.h>

stdio.h is a standard header file. The name means:

stdio
 ↓
standard input/output

It contains declarations related to standard input and output functionality. For example, functions such as:

printf()
scanf()
getchar()
putchar()

are associated with <stdio.h>,but why we need #include?

Suppose we want to use:

printf("Hello");

The compiler needs the appropriate declaration for printf(). We therefore commonly include:

#include <stdio.h>

Think of it approximately as:

Need printf()
     ↓
Where is its declaration?
     ↓
stdio.h
     ↓
#include <stdio.h>

We'll study the preprocessor and headers in much more detail later. It always starts with #.

This tells the C preprocessor that this is a preprocessing instruction.


Main Function

The main function is the entry point of a C program.

int main()

Think:

Program starts
      ↓
main()
      ↓
Statements execute

But what is int before main()?

int

The return type. It means that main() returns an integer value. For example:

return 0;

This returns the integer value 0.Conventionally:

0 → successful termination
non-zero → often used to indicate some kind of failure

The exact meaning of non-zero values depends on the program/environment.


Function Body

Look at:

int main() {

    printf("Hello");
    return 0;

}

Everything between:

{
    ...
}

is the body of the function. So:

{
    printf("Hello");
    return 0;
}

is the function body of main().

Braces:

{

}

are used to define a block of code.

Statements

Inside main() we can write statements:

printf("Hello");
return 0;

A statement is an instruction that forms part of the program. For example:

printf("Hello");

is a statement.

And:

return 0;

is another statement. Most C statements end with:

;

Whitespace

C generally ignores unnecessary spaces, tabs, and line breaks between tokens.

For example:

#include <stdio.h>

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

and:

#include <stdio.h>
int main(){printf("Hello");return 0;}

can represent the same basic program structure.

But the first version is much easier for humans to read. Therefore:

Formatting is primarily for humans; syntax is for the compiler.

Good formatting becomes extremely important as programs become larger.

Comments in Program Structure

Comments improve readability.It is not compiled by the C preprocessor.There are two types of comments:

  • Single-line comments (//)
  • Multi-line comments (/* */)
#include <stdio.h>

// Program execution starts here
int main() {
    /* My First C Program
       That prints "Hello"
    */

    // Display message
    printf("Hello");

    // End program
    return 0;
}

Combine Everything

A simple C program can be viewed as:

C Program
│
├── Preprocessor directives
│
├── Declarations
│
├── Functions
│   │
│   ├── Function return type
│   ├── Function name
│   ├── Parameters
│   └── Function body
│
└── Statements

Don't worry if some of these terms are unfamiliar. We'll introduce them one by one.

Understanding printf()

It is a function that displays text on the screen. We can pass data with or without the % specifier.e.g:

printf("Hello");
printf("%d", 10);
printf("%5d", 10);
printf("Hello");

Printing an int

#include <stdio.h>

int main() {

    int age = 25;
    int mark = 80;


    printf("%d", age);
    printf("%d", mark);

    return 0;
}

Output:

25

Printing Text and Variables Together

int age = 25;

printf("My age is %d", age);

Output:

My age is 25

This is one of the most common uses of printf().

Multiple Format Specifiers

You can print multiple values:

int age = 25;
int marks = 90;

printf("Age = %d, Marks = %d", age, marks);

Output:

Age = 25, Marks = 90

Notice:

%d → age
%d → marks

The arguments are matched from left to right, because orders are important.


Print a Newline With Escape Sequence

Escape Sequence are a character sequence that start with a backslash (\),which add a special meaning to the following character.

For example:

\n → new line
\t → tab
\\ → backslash
\" → double quote
\' → single quote
\r → carriage return
\a → bell
\0  → null character
#include <stdio.h>

int main() {

    printf("Hello\nWorld\n");
    printf("Hello\tWorld\n");
    printf("Hello\\World\n");
    printf("Hello\"World\n");
    printf("Hello\'World\n");
    printf("Hello\rWorld\n");
    printf("Hello\aWorld");

    return 0;
}

Output:

Hello
World
Hello	World
Hello\World
Hello"World
Hello'World
Hello
World
HelloWorld

Understanding scanf().

It is a function that reads data from the keyboard. Syntax:

scanf("format specifier", &variable); // &variable is the memory address

scanf("format specifier another format specifier", &variable, &variable); // multiple input variables

Example:

int age;

scanf("%d", &age);

The user can enter:

25

and the value is stored in:

age

Why &age?

scanf() needs to know where it should store the input.

The & operator obtains the address of the variable.

Think:

age
 ↓
memory location

&age
 ↓
address of age

Conceptually:

User
 ↓
25
 ↓
scanf()
 ↓
address of age
 ↓
age = 25

Complete int data type example

#include <stdio.h>

int main() {

    short int age = 20;
    int temperature = -2;
    unsigned int quantity = 10;
    long int population = 10000000L;
    long long int distance = 10000000000LL;
    int octal = 010;
    int hex = 0xF;
    int binary = 0b1010;

    // Printing Variables

    printf("Short Integer: %d\n", age);
    printf("Signed Integer: %d\n", temperature);
    printf("Unsigned Integer: %u\n", quantity);
    printf("Long Integer: %ld\n", population);
    printf("long long Integer: %lld\n", distance);
    printf("Octal: %o\n", age);
    printf("Hexadecimal: %x\n", age);
    printf("Binary: %b\n", age);
    printf("Octal To Decimal: %d\n", octal);
    printf("Hex To Decimal: %d\n", hex);
    printf("Binary To Decimal: %d\n", binary);

    // Sub-Specifier
    printf("Left %5d\n", age); //Left Space Padding
    printf("Zero %03d\n", age); //Left Zero Fill

    // Taking input

    int number;
    printf("Enter a number: ");
    scanf("%d", &number);
    printf("You entered: %d\n", number);

    return 0;
}

Output:

Short Integer: 20
Signed Integer: -2
Unsigned Integer: 10
Long Integer: 10000000
long long Integer: 10000000000
Octal: 24
Hexadecimal: 14
Binary: 10100
Octal To Decimal: 8
Hex To Decimal: 15
Binary To Decimal: 10
Left    20
Zero 020
Enter a number: 25
You entered: 25


Liked This Tutorial

Scan QR Code To Leave A Review Or

Click Here To Leave A Review
Scan QR