C Language में Printf() Scanf() Functions – Beginners

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

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

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

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

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

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

printf() एक function जिसका का उपयोग screen पर 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> // Standard input-output header file

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

    // 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

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

C language में scanf() भी एक 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> // Standard input-output header file

int main()
{
    int rollnumber; // Student roll number
    float marks;    // Student marks
    char grade;     // Student 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 होते हैं जो यह बताते हैं कि कौन-से टाइप का data (जैसे int, float, char) को screen पर कैसे display करना है।
इनका उपयोग printf() और scanf() जैसे functions के साथ किया जाता है।

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

5. Escape Sequences in C

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

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

6. 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);  // input में comma देना पड़ेगा

Correct Example:

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

7. Simple Input / Output program

इस कोड को copy करें और अपने system run करके देखें।

#include <stdio.h>  // इनपुट और आउटपुट (जैसे printf और scanf) के लिए हेडर फाइल शामिल की गई है

int main() {
    int age;  // 'age' नाम का एक int (integer) प्रकार का वेरिएबल बनाया गया है
    float perc;  // 'perc' नाम का एक float (दशमलव संख्या) प्रकार का वेरिएबल बनाया गया है

    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;  // प्रोग्राम सफलतापूर्वक पूरा हुआ, अब समाप्त हो रहा है
}

8. 8 Important Notes (Beginners के लिए)

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

9. निष्कर्ष (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 पर शेयर करके किसी की मदद करें – और खुद को भी याद दिलाएं 😊

Data type in C

Leave a Comment

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

Scroll to Top