C का पहला Program
#include <stdio.h>
int main() {
printf("text");
return 0;
}
Main Function
हर C program का execution main नाम के function के अंदर शुरू होता है -- operating system specifically इसी function को ढूंढता है और इसे पहले call करता है, चाहे आपकी file में कितने भी दूसरे functions define हों।
उदाहरण: The Main Function
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("Execution starts here, inside main.");
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Output Print करना
printf screen पर formatted text लिखता है और यही तरीका है जिससे एक C program कोई भी visible output produce करता है; इसके बिना (या किसी similar output call के बिना), आपका program perfectly चल सकता है और आपको कभी पता ही नहीं चलेगा, क्योंकि screen पर कुछ भी नहीं दिखेगा।
उदाहरण: Printing Output
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("Hello, World!");
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Zero Return करना
main से 0 return करना operating system (और आपका program launch करने वाले किसी भी script या tool) को एक signal है कि execution बिना errors के पूरा हुआ -- non-zero value return करना failure report करने का conventional तरीका है।
उदाहरण: Returning Zero
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("Program completed successfully.");
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Header Files
#include <stdio.h> C standard library से printf और scanf जैसे standard input/output functions की declarations ले आता है; इसके बिना, compiler को पता ही नहीं होगा कि ये functions exist करते हैं और यह इन्हें call करने से मना कर देगा।
उदाहरण: Header Files
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("stdio.h provides printf and scanf declarations.");
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Program Execute करना
अपना program compile करना और actually run करना -- सिर्फ इसे cleanly compile करवाना नहीं -- यह confirm करने का इकलौता तरीका है कि यह वैसे ही behave करता है जैसी आपने उम्मीद की थी; zero compiler errors वाला program भी पूरी तरह गलत output produce कर सकता है।
उदाहरण: Executing the Program
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Declare result and set it to 5 / 2
int result = 5 / 2;
// Print formatted text to the screen
printf("Result: %d", result);
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
#include <stdio.h>भूल जाना, ताकिprintfundeclared रहे और compiler warn करे या fail हो जाए।printf("Hello")में\nछोड़ देना, ताकि shell prompt text के ठीक बाद दिखे।int main()की बजायvoid main()इस्तेमाल करना, जो portable standard C नहीं है।
Chapter Quiz — Complete all 21 topics to unlock
0/21 topics done
Complete these topics first:
- C Introduction
- C History & Features
- C Environment Setup
- C First Program
- C Syntax & Structure
- C Statements
- C Comments
- C Keywords & Identifiers
- C Data Types
- C Character Data Type
- C Numeric Data Types
- C Decimal (Floating-Point) Numbers
- C sizeof Operator
- C Extended Data Types
- C Type Conversion
- C Booleans
- C Variables
- C Changing Variable Values
- C Multiple Variables
- C Constants
- C Fixed-Width Integers