🟢 Beginner  ·  Lesson 04

पहला Program – Hello World

आपका पहला C Program

Programming में tradition है कि किसी भी language में पहला program "Hello, World!" screen पर print करता है। यह test करता है कि आपका development environment सही setup हुआ है।

hello.c
#include <stdio.h>

int main() {
    printf("Namaste Duniya!\n");
    return 0;
}
Namaste Duniya!

Line-by-Line Explanation

Line 1: #include <stdio.h>

यह एक preprocessor directive है। यह compiler को कहता है कि stdio.h (Standard Input Output) header file को include करे। इस file में printf() और scanf() की definition है। इस line के बिना, compiler printf को नहीं पहचानेगा।

Line 2: int main() { }

यह main function है — हर C program का entry point। जब आप C program run करते हैं, execution हमेशा main() से शुरू होती है।

Line 3: printf("Namaste Duniya!\n");

printf() एक library function है जो text screen पर print करता है। Double quotes के अंदर का text string literal कहलाता है। \n newline escape sequence है — यह cursor को अगली line पर ले जाता है।

Line 4: return 0;

return 0; operating system को 0 return करता है, जो बताता है कि program successfully चला। Non-zero value typically error indicate करती है।

Compile और Run कैसे करें

Terminal / Command Prompt
# Step 1: hello.c नाम से save करें
# Step 2: Compile करें
gcc hello.c -o hello

# Step 3: Run करें (Linux/Mac)
./hello

# Step 3: Run करें (Windows)
hello.exe

Common Errors

ErrorकारणFix
stdio.h not found#include missing#include <stdio.h> add करें
Missing ;Semicolon भूल गएprintf के बाद ; add करें
undefined reference to mainmain function नहीं हैint main() { } लिखें

सारांश

  • हर C program main() से execute होना शुरू होता है
  • #include <stdio.h> printf और scanf के लिए ज़रूरी है
  • Statements semicolon ; से खत्म होते हैं
  • Code blocks curly braces { } में होते हैं
  • printf() text display करता है, \n अगली line पर जाता है
  • return 0; successful completion signal करता है

अक्सर पूछे जाने वाले प्रश्न (FAQ)

C में Hello World program कैसे लिखें?
आप #include <stdio.h> से standard input-output header शामिल करते हैं, एक main function लिखते हैं, और उसके अंदर printf("Hello, World!"); call करते हैं, return 0; से समाप्त करते हुए। उसे compile करके चलाने पर screen पर text छपता है।
C में #include का क्या मतलब है?
यह compiler को Standard Input Output library शामिल करने को कहता है, जो printf और scanf जैसे functions देती है। इस line के बिना program को पता नहीं होता कि printf क्या है और वह compile नहीं होगा।
C में main function क्या है?
main हर C program का शुरुआती बिंदु है — execution हमेशा वहीं से शुरू होता है। इससे पहले int का मतलब है कि यह operating system को एक integer लौटाता है, और return 0; संकेत देता है कि program सफलतापूर्वक समाप्त हुआ।
main के अंत में return 0 क्यों लिखते हैं?
return 0; operating system को बताता है कि program बिना errors के समाप्त हुआ। शून्य पारंपरिक रूप से सफलता दर्शाता है, जबकि non-zero value बताती कि execution के दौरान कुछ गलत हुआ।
C program compile और run कैसे करें?
आप code को .c file में सहेजते हैं, gcc जैसे compiler से compile करते हैं — जैसे gcc hello.c -o hello — और फिर बने program को ./hello से चलाते हैं। Online compilers बिना कुछ install किए यही कर सकते हैं।
← Back to C Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.