17.6.25

20250617 21:00 Chapter 1 : First Steps in 'C'


🏠 Homepage Next Chapter →
                                          




What is 'C'?

'C' is a language we use to talk to computers.
It was made by a smart man named Dennis Ritchie in 1972.

We use it to make:

  • Computer brains (like Windows not the house windows.)

  • Smart machines (like washing machines, microwaves)

  • Fun games (like Mario or car racing games)

In English:

A B C... → Make Words → Form Sentences → Write Stories

In C:

A, 1, +, = → Make Variables → Write Instructions → Build Programs

Building Blocks of C

C Character Set:

  • Letters: A-Z, a-z

  • Numbers: 0–9

  • Symbols: +, -, =, ;, { }

  • Space, Tab, Enter

Constants (Fixed Values)

1. Integer: 10, -25
2.Real (Decimal): 3.14, -2.5
3. Character: 'A', '9', '+'

Bonus types (used later): arrays, pointers, etc.

What is a Variable?

A variable is like a box 
You can store values and change them later!

Types:

  • int → whole numbers (10, -5)

  • float → decimal numbers (3.14)

  • char → single letters ('A')

Naming Variables (Rules)

 Good: marks, total_1, _score
 Bad: 1mark, my-name, rate$

What are Keywords?

Special words C already understands!

Examples: int, if, for, return

You can’t use them as your own variable names!

First Program in C

/* Simple Interest Calculator */

main()

{
    int p, n;
    float r, si;

    p = 1000;
    t = 3;
    r = 8.5;

    si = p * t * r / 100;

    printf("%f", si);
}

What’s Happening?

main() – Program starts here

  • int, float – We make boxes (variables)

  • /* */ – Comments for humans 

  • si = p * t * r / 100; – Math formula

  • printf() – Show the answer on screen!

printf() Examples

printf("Hello"); // Show words

printf("%d", 5);         // Show number
printf("%f", 5.5);       // Show decimal
printf("%c", 'A');       // Show letter

\n = Go to new line
Example: printf("Hi\nBye");

Output:

Hi  
Bye

Expressions

Expressions = Math or logic stuff
Examples:

  • 3

  • a + b

  • x * y / 100

You can also print them:
printf("%d", 5 + 3); → 8


No comments:

Post a Comment

rating System

Loading...

Understanding Arrays in C

The Bookshelf Analogy & Book-Author Example Arrays are one of the most essential concepts in C programming. They let you store multiple ...