🏁 Day 1: C from Zero to Hero – Getting Started
Welcome to your first step on the journey from complete beginner to C expert! Today we’ll cover:
1. What is C?
2. Your first C program
3. Compilation & execution (simple)
4. Basic input/output
5. Homework exercises
1. What Is C?
C is a general-purpose, high-performance programming language created in the 1970s.
It gives you direct control over memory and system resources.
C is the foundation for many other languages (C++, Java, Python internals).
2. Your First C Program: “Hello, World!”
Every language tutorial starts with this classic. It shows you the minimal structure you need.
CopyEdit
#include <stdio.h> // 1) Tell the compiler you’ll use standard I/O functions
int main(void) { // 2) main() is where your program starts
printf("Hello, World!\n"); // 3) Print text to the screen
return 0; // 4) Return 0 → “I finished successfully”
Explanation:
1. #include <stdio.h>
Imports the Standard Input/Output library so you can use printf().
2. int main(void)
The entry point of every C program.
3. printf("…");
Prints text to your console.
4. return 0;
Signals to the operating system that everything ran fine.
3. Compile & Run (Simplified)
1. Save the code as hello.c.
2. Open your terminal (or Code::Blocks/VS Code built-in terminal).
3. Type:
cpp
CopyEdit
gcc hello.c -o hello // “gcc” compiles, “-o hello” names the output
./hello // Run the compiled program
4. You should see:
CopyEdit
Hello, World!
4. Basic Input & Output
Let’s extend “Hello, World!” to ask the user their name and greet them.
CopyEdit
#include <stdio.h>
int main(void) {
char name[50]; // Reserve space for up to 49 chars + null
printf("Enter your name: "); // Prompt
scanf("%49s", name); // Read a word (no spaces) safely
printf("Hello, %s! Welcome to C.\n", name);
return 0;
char name[50]; creates a text buffer of length 50.
scanf("%49s", name); reads up to 49 characters, preventing overflow.
5. Day 1 Homework
1. Write & Run the two programs above (Hello World and Name Greeter).
2. Experiment: Change the prompt to ask for your favorite number:
o Read an int using scanf("%d", &num);
o Print “Your favorite number is X”.
3. Answer in your own words:
o What does #include <stdio.h> do?
o Why do we use return 0; in main()?
o What happens if you omit -o hello when compiling?
When you’ve tried these, share:
What worked?
Any errors you saw?
Anything you found confusing?
I’ll help you debug and clarify. Tomorrow we’ll build on this with variables, data types, and more I/O.
Good luck!
You said:
give all in pdf
ChatGPT said:
It seems like I can’t do more advanced data analysis right now. Please try again later.
If you'd like, I can give you the Day 1 content in plain text format so you can copy and paste it into a
document (Word or Google Docs) and save it as a PDF yourself. Would you like me to do that?
You've reached your data analysis limit.
Upgrade to ChatGPT Plus or try again tomorrow after 9:17 PM.
Get Plus