Chapter 12: Introduction to C Language ๐¶
Mentor's Note: C is the mother of all modern languages (like Java and Python). If you understand how C works, you will understand how the computer's heart beats! ๐ก
๐ The Scenario: The Chef's Recipe ๐จโ๐ณ¶
Imagine you are a Chef in a busy restaurant in Rustompura.
- The Problem: You want to teach a new assistant how to make your famous Biryani. ๐ฒ
- The Logic (The Code): You write a Step-by-Step Recipe. "1. Boil water. 2. Add rice. 3. Mix spices."
- The Translation (The Compiler): The assistant only speaks a different language. You need a Translator (The Compiler) to convert your recipe into a language the assistant understands.
- The Result: A delicious meal! In programming, the Recipe is your C Code, and the Assistant is the Computer CPU. โ
๐ Concept Explanation¶
1. What is C?¶
C is a general-purpose, procedural programming language developed in 1972 by Dennis Ritchie at AT&T Bell Labs.
2. Key Features:¶
- Middle-Level Language: It combines features of both high-level (easy to read) and low-level (fast like machine code).
- Portable: Code written on one computer can run on another.
- Structured: You can break big programs into small functions.
3. The Compiler ๐ ๏ธ¶
Computers only understand 0s and 1s. A Compiler is a special software that converts your C code (human-readable) into machine code (computer-readable).
๐จ Visual Logic: The C Journey¶
graph LR
A[Source Code: .c ๐] -- Compiler ๐ ๏ธ --> B[Machine Code: .exe ๐ข]
B --> C[Computer CPU ๐ง ]
C --> D[Output โ
]
๐ป Implementation: Your First C Program¶
```c // ๐ Scenario: Welcoming a new student // ๐ Action: Using the printf function
include // ๐ฆ Library for Input/Output¶
int main() { // ๐ค Printing message to screen printf("Hello, GSEB Student! Welcome to C. ๐
");
return 0; // โ
Success!
}
// ๐๏ธ Outcome: Text appears on the black screen (terminal).
```
๐ง Step-by-Step Logic¶
- Start ๐
- Link Header: Use
#include <stdio.h>to get the printing tools. - The Brain: Start the
main()function. Every C program starts here. - Action: Use
printfto display text. - Finish: Use
return 0to tell the computer we are done. - End ๐
๐ Sample Dry Run¶
| Step | Action | Description |
|---|---|---|
| 1 | Load stdio.h |
Setup printing tool ๐ฅ |
| 2 | Enter main() |
Start the engine โ๏ธ |
| 3 | printf(...) |
Push text to display ๐ค |
| 4 | return 0 |
Turn off engine โ |
๐งช Interactive Elements¶
Try It Yourself¶
Hands-on Exercise
Task: Modify the C code above to print your School Name on the second line. Hint: Use `
at the end of the firstprintf` to start a new line! ๐ก
Quick Quiz¶
- Who developed the C language?
- A) James Gosling
- B) Dennis Ritchie
- C) Guido van Rossum
- D) Bill Gates
Answer: B - Dennis Ritchie.
๐ก Board Exam Focus (GSEB Std 10) ๐¶
- Important: In Std 10, examiners often ask for the file extension of a C program.
- Answer: The extension is
.c.
๐ Best Practices¶
- Case Sensitive: Remember,
printfis NOT the same asPrintf. Always use lowercase for keywords! โ ๏ธ
๐ก Pro Tip: "C is quirky, flawed, and an enormous success." - Dennis Ritchie