Namaskar Doston
Agar aap C programming seekh rahe hain, toh sabse pehla concept jo aapko aana chahiye wo hai Input aur Output.
C language me user se data lena (input) aur output screen par dikhana (output) ek basic but powerful skill hai.
Is article me hum samjhenge:
- C language me input output kaise hota hai
printf()
aurscanf()
functions kya hote hain- Examples ke saath samjhayenge
- Common mistakes bhi dekhenge
C Language Me Input Output Kya Hota Hai?
Input Kya Hota Hai?
Jab user kuch data program ko deta hai (jaise number, naam, etc.), usse input kehte hain.
Output Kya Hota Hai?
Jab program koi result ya message screen par dikhata hai, usse output kehte hain.
Example (Real Life)
ATM me jab aap amount enter karte ho – vo input hota hai.
Aur jab screen par balance show hota hai – vo output hota hai.
Yahi logic C language me bhi apply hota hai.
printf() Function in C
printf() Kya Hai?
printf()
ka use screen par output dikhane ke liye hota hai, jaise message ya variable value.
Syntax
printf("format string", variable);
Example
int age = 20;
printf("Meri age hai %d", age);
Common Format Specifiers in printf()
Format | Data Type | Example Use |
---|---|---|
%d | Integer | printf("%d", age); |
%f | Float | printf("%f", pi); |
%c | Character | printf("%c", grade); |
%s | String | printf("%s", name); |
Multiple Values Print Karna
int roll = 101;
char grade = 'A';
printf("Roll No: %d, Grade: %c", roll, grade);
scanf() Function in C
scanf() Kya Hai?
scanf()
function ka use user se input lene ke liye hota hai.
Syntax
scanf("format string", &variable);
Note:
&
ka matlab hota hai address of variable. Yahaan input value store hoti hai.
Example
int marks;
scanf("%d", &marks);
Multiple Inputs Ek Saath
int a, b;
scanf("%d %d", &a, &b);
printf() aur scanf() Me Difference
Function | Purpose | Direction | Example |
---|---|---|---|
scanf() | Input lena | User → Program | scanf("%d", &x); |
printf() | Output dena | Program → User | printf("Value: %d", x); |
Common Mistakes Jo Beginners Karte Hain
1. &
Lagana Bhool Jana
int x;
// Galat
scanf("%d", x);
// Sahi
scanf("%d", &x);
Kyu galat hai?scanf()
ko memory address chahiye jahan value store karni hai. Agar &
nahi lagayenge toh program crash ya galat result de sakta hai.
2. Galat Format Specifier Use Karna
float pi = 3.14;
// Galat
printf("%d", pi);
// Sahi
printf("%f", pi);
Kyu galat hai?%d
sirf integers ke liye hota hai. Float values ke liye %f
use karna chahiye.
Practice Ke Liye Simple Programs
Program 1: Naam Aur Umar Input Aur Output
char name[30];
int age;
scanf("%s", name);
scanf("%d", &age);
printf("Namaste %s, aapki age hai %d", name, age);
Program 2: Do Numbers Ka Sum
int a, b;
scanf("%d %d", &a, &b);
printf("Sum = %d", a + b);
Helpful Resource for Beginners
Agar aap C ke aur input-output examples dekhna chahte hain, toh yeh guide bhi helpful ho sakti hai:
W3Schools – C Input and Output
Yahaan aapko aur examples aur explanation milega in simple English.
FAQs – Sabse Zyada Poochhe Jane Wale Sawal
Q1. scanf() me &
kyu lagta hai?
Ans: Kyunki C language me value memory address par store hoti hai, aur scanf()
ko wahi address chahiye.
Q2. printf() se input le sakte hain kya?
Ans: Nahi. printf()
sirf output ke liye hota hai. Input ke liye scanf()
use hota hai.
Q3. %d
aur %f
me kya difference hai?
Ans:
%d
– Integers ke liye%f
– Decimal/Float values ke liye
Conclusion
Ab aapko clearly samajh aa gaya hoga ki c language me input output kaise hota hai aur kaise printf()
aur scanf()
functions use kiye jaate hain.
Agar aap syntax, format specifiers aur common mistakes ka dhyan rakhte ho, toh input/output wala part aapke liye easy ho jayega.
Practice karte rahiye, coding me confidence aayega aur basic concepts strong banenge.
Next Article Padhein:
C Language Syntax aur Tokens – Hinglish Me Simple Guide (2025)
Agar aapko yeh article helpful laga ho to ise share karein, comment karein, aur apne doston ko bhi recommend karein.
Next article kis topic par chahiye? Comment karke zarur batao.
Written by: Aditya (Programming Sikho)