Chapter 12: Introduction to C Language πΒΆ
Prerequisites: Basic computer knowledge
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