C Language Printf() Scanf() Function – हिंदी में समझें

printf() और scanf() Functions क्या होते हैं?

C language printf() scanf() ये दोनों predefined functions हैं, जो stdio.h (standard input output headerfile) में define है। scan() और print() function का उपयोग Console पर जानकारी को display और user से जानकारी input करनवाने के लिए किया जाता है। इसे हम ऐसे सोंच सकते कि अगर हमारे पास एक कंप्यूटर है लेकिन मॉनिटर नहीं — क्या हम जान पाएंगे कि उसमें क्या चल रहा है?
ठीक उसी तरह, अगर किसी प्रोग्राम में printf() और scanf() जैसे function न हो , तो हम user से न कोई जानकारी input ले सकता है और न कुछ display कर सकते है। इस लिये printf() और scanf() function एक programmer और user के लिए बहोत जरुरी है, यह दोनों function बहोत ज्यादा use भी किये जाते है।

इसलिये इस आर्टिकल में हम जानेंगे कि ये printf() और scanf() function कैसे काम करते हैं, कैसे इनका सही syntax लिखा जाता है, और कौन-कौन से छोटी छोटी चीज़ों को जानना एक beginner ज़रूरी है।

printf() और scanf Functions का उपयोग कहाँ होता है?

  • massage को display करने के लिए और यूजर से input लेने के लिए
  • Menu driven program में जैसे – calculator, atm machine etc.
  • Program को interactive बनाने के लिए
c language printf() scanf()

C language में Printf() Function कैसे use करें ?

printf() एक function जिसका का उपयोग console पर text, numbers, variables या formatted output दिखाने के लिए किया जाता है।

Syntax:

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

 Explanation:

“format string” – इसमें format specifiers होते हैं जैसे %d, %f, %s आदि

variable1, variable2 – जिन values को print करना है

Example:

int age = 25;

printf(“Age is: %d”, age);

Example Code :

#include <stdio.h> 

int main()
{
    int rollnumber = 45543; 
    float marks = 300.00; 
    char grade = 'A';     

    // Display output
    printf("\nWelcome to Anwarcodes.com\n");
    printf("Roll Number: %d\n", rollnumber);
    printf("Marks: %.2f\n", marks); // %.2f prints 2 decimal places
    printf("Grade: %c\n", grade);

    return 0; // End of program
}

Output:

Welcome to Anwarcodes.com
Roll Number: 45543
Marks: 300.00
Grade: A

C language में Scanf() कैसे use करें ?

C language में scanf() function एक library function है, जिसका का उपयोग user से data input लेने और उसे variable में store करने के लिए किया जाता है।

Syntax:

scanf(“format string”, &variable1, &variable2, …);

int age = 25;

printf(“Age is: %d”, age);

 Explanation:

format string – बताता है कि user से किस type का data लेना है

&variable – variable का address देना जरूरी है (क्योंकि scanf() value को variable के address पे memory में store करता है। )

 Example:

int age;

scanf(“%d”, &age);

Example Code:

#include <stdio.h> 

int main()
{
    int rollnumber; 
    float marks;    
    char grade;     

    // Roll number input
    printf("Enter your roll number: ");
    scanf("%d", &rollnumber);

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

    // Grade input (space before %c to ignore leftover newline)
    printf("Enter your grade: ");
    scanf(" %c", &grade);

    // Display output
    printf("\nWelcome to Anwarcodes.com\n"); // Display massage
    printf("Roll Number: %d\n", rollnumber);
    printf("Marks: %.2f\n", marks); // %.2f prints 2 decimal places
    printf("Grade: %c\n", grade);

    return 0; // End of program
}

Otuput :

Enter your roll number: 45543
Enter your marks: 300
Enter your grade: A

Welcome to Anwarcodes.com
Roll Number: 45543
Marks: 300.00
Grade: A

Common Format Specifiers in C

C language में Format Specifiers ऐसे symbols होते हैं जो यह बताते हैं कि कौन-से type का data (जैसे int, float, char) को screen पर कैसे display करना है।
इनका उपयोग printf() और scanf() जैसे functions के साथ किया जाता है।

निचे कुछ Format Specifier दिए गए हैं :

FormatTypeExampleOutput
%dint3030
%ffloat/double12.5234512.523450
%cchar‘a’a
%sstring“Hello”Hello

Escape Sequences in C Language

Escape sequences ऐसे special characters होते हैं जो output formatting के लिए use किए जाते हैं।
ये हमेशा backslash (\) से शुरू होते हैं। निचे common Escape Sequence दिए हैं।

Common Escape Sequences:

Escapeकाम (Meaning)
\nNew line (नई लाइन) के लिये
\tTab space (टैब स्पेस) के लिये
\\Backslash print करने के लिये
\”Double quote दिखाने के लिये
\’Single quote के लिये
\rCarriage return
\bBackspace
\aAlert/beep sound
\vVertical tab (rarely used)

Example – New Line (\n):

printf(“First line\nSecond line”);

Output:

First line  

Second line

Example – Tab Space (\t):

printf(“A\tB\tC”);

Output:

A       B       C

Semicolon (;) और Comma (,) का सही उपयोग

Semicolon (;) क्या होता है?

  • हर statement के end में ; लगाना ज़रूरी है
  • यह बताता है कि एक command complete हो गया है
  • बिना semicolon के code compile नहीं होता है

int x = 10;     // सही  

printf(“%d”, x); // सही

int y = 20      // गलत — semicolon missing

Comma (,) कहाँ use होता है?

  • Multiple variables declare करने में
  • printf() और scanf() या किसी और function के arguments को अलग करने के लिए
int a = 5, b = 10, c = 15;
printf("a = %d, b = %d", a, b);
scanf("%d %d", &a, &b);

Incorrect Example:

scanf(“%d,%d”, &a, &b);  // %d,%d यह गलत है क्यों की यहां comma लगाने की जरुरत नहीं है।

Correct Example:

scanf(“%d %d”, &a, &b);  // space-separated input यह सही

Simple Input / Output program

इस कोड को copy करें और अपने system में run करके देखें। इससे printf() और scanf() को समझने में मदद मिलेगी।

#include <stdio.h>

int main() {
    int age; 
    float perc;

    printf("Enter Your age : ");  // user से उसकी उम्र पूछी जा रही है
    scanf("%d", &age);  // user द्वारा दी गई उम्र को 'age' वेरिएबल में स्टोर किया जा रहा है

    printf("\nEnter Percentage : ");  // user से प्रतिशत (percentage) पूछा जा रहा है
    scanf("%f", &perc);  // user द्वारा दिया गया percentage 'perc' वेरिएबल में स्टोर किया जा रहा है

    // user की दी गई उम्र और percentage को स्क्रीन पर दिखाया जा रहा है
    printf("\nYou have enter age : %d\nYour have enterd percentage : %f", age, perc);

    return 0;
}

Important Notes (Beginners के लिए)

  • हर statement को ; से खत्म करना अनिवार्य है
  • scanf() में हर variable से पहले & ज़रूर लगाएं pointer को छोड़कर
  • printf() में output को print करने के लिए सही format specifier इस्तेमाल करें
  • Float के लिए %f, और int के लिए %d का use करें
  • scanf() में formate specifier के साथ commas avoid करें, space ही बेहतर है
  • Escape sequences जैसे \n, \t output को readable बनाते हैं
  • printf() default 6 decimal places तक float print करता है
  • Format string और variable type mismatch से runtime errors आते हैं

निष्कर्ष (Conclusion)

  • C Language में printf() और scanf() functions के बिना कोई meaningful program नहीं लिखा जा सकता
  • Escape sequences से output ज्यादा readable और format-friendly बनता है
  • Syntax की छोटी-छोटी गलतियाँ (जैसे semicolon भूल जाना) compile errors दे सकती हैं
  • Comma और Semicolon का सही उपयोग सीखना जरूरी है
  • Practice से ही perfect understanding आएगी

अपने Doubts या Feedback नीचे Comment करें
अगर आपको इस लेख में कोई confusion है या कोई और टॉपिक चाहते हैं, तो नीचे comment करना न भूलें।
आपका सवाल अगली पोस्ट का विषय बन सकता है!

इस पोस्ट को Share करें
अगर आपको यह जानकारी मददगार लगी हो, तो इसे अपने दोस्तों के साथ शेयर करें जो C Language सीख रहे हैं। WhatsApp, Telegram, या Facebook पर शेयर करके किसी की मदद करें – और खुद को भी याद दिलाएं

Leave a Comment

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

Scroll to Top