Printf और Scanf in C in Hindi – Complete Beginner Guide

आज आप पढ़ने वाले हैं Printf and Scanf in C in Hindi एक दम आसान Explanation के साथ। printf() और scanf() functions C language की नींव हैं — बिना इन्हें जाने आप कोई भी program ठीक से नहीं बना सकते। चाहे आप student हों, job की तैयारी कर रहे हों, या बस coding सीखने का शौक रखते हों — यह guide आपके लिए ही लिखी गई है।

इस Printf and Scanf in C in Hindi guide में हम बिल्कुल शुरुआत से समझेंगे कि printf() और scanf() क्या होते हैं, ये कैसे काम करते हैं, और इन्हें program में कैसे use करते हैं। हर concept को आसान हिंदी में, real examples के साथ explain किया गया है ताकि आपको कहीं अटकना न पड़े।

इस पूरी post को पढ़ने के बाद आप जान जाएंगे कि screen पर output कैसे print करते हैं, user से input कैसे लेते हैं, format specifiers क्या होते हैं, और common गलतियों से कैसे बचें। तो चलिए शुरू करते हैं!

C Language में Input और Output क्यों जरूरी है?

किसी भी program का काम होता है — कुछ data लेना, उसे process करना, और result दिखाना। इसी को हम Input/Output (I/O) कहते हैं।

C language में input और output के लिए सबसे ज्यादा use होने वाले दो functions हैं:

  • printf() — screen पर कुछ print (दिखाना) करने के लिए
  • scanf() — user से keyboard के जरिए input लेने के लिए

ये दोनों functions stdio.h नाम की header file में होते हैं, इसलिए हर C program की शुरुआत में #include<stdio.h> लिखना जरूरी होता है।

Printf in C क्या है? (Printf Function की पूरी जानकारी)

printf() का मतलब है “Print Formatted” — यानी formatted तरीके से screen पर कुछ दिखाना।

Printf का Basic Syntax:

printf(“Write text here”);

जब variable की value दिखानी हो:

printf(“format string”, variable1, variable2, …);

Example Program — Hello World

#include <stdio.h>
 
int main() {
	printf("Hello, World!");
	return 0;
}
▶️ Output Result
Hello, World!

यह C का सबसे पहला और सबसे famous program है। printf() ने यहाँ “Hello, World!” को screen पर print किया।

Printf के साथ Variable Value Print करना

अगर हमें किसी variable की value print करनी हो, तो हमें format specifier use करना होता है।

#include <stdio.h>

int main() {

    int age = 20;

    // Printing the age
    printf("My age is: %d years\n", age);

    return 0;
}
▶️ Output Result
My age is: 20 years

यहाँ %d एक format specifier है जो integer (पूरी संख्या) के लिए use होता है।

Format Specifiers क्या होते हैं?

Format specifiers वो special codes होते हैं जो बताते हैं कि किस type का data print करना है या input लेना है।

Format SpecifierData TypeExample
%dInteger (int)10, -5, 100
%fFloat (दशमलव संख्या)3.14, 9.8
%cCharacter (एक अक्षर)‘A’, ‘z’
%sString (शब्द/वाक्य)“Rahul”, “Hello”
%lfDouble (बड़ी दशमलव संख्या)3.14159265
%ldLong Integer1000000

Example Program — अलग-अलग Data Types Print करना

#include <stdio.h>

int main() {

    int marks = 95;
    float percentage = 95.5;
    char grade = 'A';

    // Printing student details
    printf("Marks      : %d\n", marks);
    printf("Percentage : %.2f%%\n", percentage);
    printf("Grade      : %c\n", grade);

    return 0;
}
▶️ Output Result
Marks : 95 Percentage : 95.50% Grade : A

यहाँ \n का मतलब है new line — यानी अगला text नई line पर आएगा। और %.2f का मतलब है दशमलव के बाद सिर्फ 2 अंक दिखाओ।

Printf के साथ Escape Sequences

Escape sequences वो special characters हैं जो \ (backslash) के साथ लिखे जाते हैं। निचे दिए गए Table में कुछ common Escape Sequences दिए गये हैं।

Escape Sequencesकाम
\nNew line (नई लाइन)
\tTab space
\\Backslash print करना
\”Double quote print करना
\rCarriage return

निचे इस Program में \t और \n का use किया गया है, इसी तरह बाकी के Escape Sequence को अपने program में use करके check करें।

#include<stdio.h>
int main()
{
printf("Naam:\tRahul\n");
printf("Sheher:\tDelhi\n");
return 0;
}
▶️ Output Result
Naam: Rahul Sheher: Delhi

Scanf in C क्या है? (Scanf Function की पूरी जानकारी)

अब बात करते हैं Scanf function जो User से input लेने के लिए इस्तेमाल करते हैं : 

scanf() का मतलब है “Scan Formatted” — यानी user से formatted तरीके से input लेना।

Scanf का Basic Syntax

scanf(“format specifier”, &variable);

यहाँ & (ampersand) बहुत जरूरी है — यह variable का address देता है जहाँ input Value store होगी।

Scanf Example Program

#include <stdio.h>

int main() {

    int age;

    // Taking age input from the user
    printf("Enter your age: ");
    scanf("%d", &age);

    // Displaying the entered age
    printf("Your age is: %d years\n", age);

    return 0;
}
▶️ Output Result
Enter your age: 21 Your age is: 21 years

एक साथ Multiple Inputs लेना

#include <stdio.h>

int main() {

    int a, b, sum;

    // Taking first number input
    printf("Enter the first number: ");
    scanf("%d", &a);

    // Taking second number input
    printf("Enter the second number: ");
    scanf("%d", &b);

    // Calculating the sum
    sum = a + b;

    // Displaying the result
    printf("The sum of both numbers is: %d\n", sum);

    return 0;
}
▶️ Output Result
Enter the first number: 15 Enter the second number: 25 The sum of both numbers is: 40
Printf and Scanf in C in Hindi

Printf और Scanf को एक साथ Use करना — Complete Programs

अब हम Printf and Scanf in C in Hindi के कुछ complete programs देखेंगे जहाँ दोनों functions एक साथ काम करते हैं। 

Scanf and Printf Complete Program 1: Student की जानकारी Input लेना और Print करना

#include <stdio.h>

int main() {

    char name[50];
    int age;
    float marks;

    printf("=== Student Information ===\n");

    // Taking student name input
    printf("Enter your name: ");
    scanf("%s", name);

    // Taking age input
    printf("Enter your age: ");
    scanf("%d", &age);

    // Taking marks input
    printf("Enter your marks: ");
    scanf("%f", &marks);

    // Displaying student information
    printf("\n--- Your Information ---\n");

    printf("Name  : %s\n", name);
    printf("Age   : %d years\n", age);
    printf("Marks : %.2f\n", marks);

    return 0;
}
▶️ Output Result
=== Student Information ===Enter your name: Anwar Enter your age: 21 Enter your marks: 88.5— Your Information — Name : Anwar Age : 21 years Marks : 88.50

Scanf and Printf Complete Program 2:

#include <stdio.h>

int main() {

    float num1, num2;

    // Taking first number input
    printf("Enter the first number: ");
    scanf("%f", &num1);

    // Taking second number input
    printf("Enter the second number: ");
    scanf("%f", &num2);

    // Performing arithmetic operations
    printf("\nAddition       : %.2f\n", num1 + num2);
    printf("Subtraction    : %.2f\n", num1 - num2);
    printf("Multiplication : %.2f\n", num1 * num2);

    // Checking division by zero
    if(num2 != 0)
        printf("Division       : %.2f\n", num1 / num2);
    else
        printf("Division is not possible (cannot divide by zero)\n");

    return 0;
}
▶️ Output Result
Enter the first number: 20 Enter the second number: 5Addition : 25.00 Subtraction : 15.00 Multiplication : 100.00 Division : 4.00

Printf और Scanf में Common Mistakes (और उनसे कैसे बचें)

Printf and Scanf in C in Hindi में सीखते समय beginners अक्सर ये गलतियाँ करते हैं:

गलती 1: & भूल जाना

गलत :

scanf(“%d”, age);

सही :

scanf(“%d”, &age);

scanf() में & जरूरी है। बिना & के program crash हो सकता है।

गलती 2: गलत Format Specifier Use करना

float price = 99.99;

गलत :

printf(“%d”, price);  // int ke liye %d, float ke liye nahi!

सही :

printf(“%f”, price);

गलती 3: stdio.h Header Include न करना

गलत :

int main() {

printf(“Hello”);  // stdio.h nahi hai!

}

सही :

#include <stdio.h>

int main() {

printf(“Hello”);

}

गलती 4: String के साथ & लगाना

char name[50];

गलत :

scanf(“%s”, &name);

सही :

scanf(“%s”, name);  // String (array) mein & nahi lagate

Printf में Width और Precision Control करना

यह थोड़ा advanced topic है, लेकिन बहुत useful है।

#include <stdio.h>

int main() {

    // Right aligned in 10 character space
    printf("%10d\n", 42);

    // Left aligned in 10 character space
    printf("%-10d|\n", 42);

    // Printing float with 3 decimal places
    printf("%.3f\n", 3.14159);

    // Width 8, 2 decimal places
    printf("%8.2f\n", 3.14159);

    return 0;
}
▶️ Output Result
42 42 | 3.142 3.14

Scanf से Multiple Values एक साथ लेना

#include <stdio.h>

int main() {

    int x, y;

    // Taking two numbers as input
    printf("Enter two numbers separated by a space: ");
    scanf("%d %d", &x, &y);

    // Displaying the entered numbers
    printf("You entered: %d and %d\n", x, y);

    return 0;
}
▶️ Output Result
Enter two numbers separated by a space: 10 20 You entered: 10 and 20

User 10 20 type करेगा और Enter दबाएगा — दोनों values अलग-अलग variables में store हो जाएंगी। 

Conclusion ( निष्कर्ष )

Printf and Scanf in C in Hindi की यह complete guide यहीं समाप्त होती है। हमने शुरू से लेकर आखिरी तक सब कुछ cover किया — printf() से output दिखाना, scanf() से input लेना, format specifiers की पूरी list, escape sequences, common mistakes और उनके solutions, और कई real examples के साथ practice programs। अब आपके पास वो सारी जानकारी है जो एक C programmer को शुरुआत में चाहिए होती है।

अब बारी है practice की! सिर्फ पढ़ने से coding नहीं आता — अपने computer पर compiler install करें (जैसे Code::Blocks या GCC), ऊपर दिए गए सभी programs खुद type करके run करें, और फिर उनमें बदलाव करके देखें क्या होता है। अगर कोई doubt हो तो नीचे comment करें। और अगर यह post helpful लगी हो, तो इसे अपने दोस्तों के साथ जरूर share करें जो C programming सीख रहे हैं!

Frequently Asked Questions

Q 1: Printf और Scanf में क्या अंतर है?
Ans: Printf and Scanf in C in Hindi सीखने के लिए यह सबसे basic concept है — printf() output के लिए और scanf() input के लिए। दोनों stdio.h header file में होते हैं और दोनों format specifiers use करते हैं, लेकिन scanf() में variable के आगे & लगाना जरूरी होता है।
Q 2: Scanf में & क्यों लगाते हैं?
Ans: & (address-of operator) variable का memory address देता है। scanf() को यह जानना होता है कि input किए गए data को memory में कहाँ store करना है। बिना & के function को पता ही नहीं चलेगा कि data कहाँ रखें, और program crash हो सकता है। Note: character array (string) के साथ & नहीं लगाते क्योंकि array का नाम खुद ही उसका address होता है।
Q 3: %d और %f में क्या फर्क है?
Ans: %d integer (बिना दशमलव वाली पूरी संख्या जैसे 5, 100, -3) के लिए use होता है। %f float (दशमलव वाली संख्या जैसे 3.14, 9.8) के लिए use होता है। गलत specifier use करने पर output गलत आएगा।
Q 4: क्या एक printf में कई variables print कर सकते हैं?
Ans: हाँ, बिल्कुल! आप एक ही printf() में कई format specifiers और उनके corresponding variables list कर सकते हैं। उदाहरण: printf(“Naam: %s, Age: %d”, name, age); — यहाँ दो variables एक साथ print हो रहे हैं।
Q 5: अगर stdio.h include न करें तो क्या होगा?
Ans: अगर #include नहीं लिखा तो compiler को printf() और scanf() की definition नहीं मिलेगी और program compile नहीं होगा। आपको “implicit declaration” जैसी error आएगी। इसलिए C के हर program में जहाँ input/output use हो, यह line लिखना अनिवार्य है।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top