C Environment का Setup
In this page:
Compiler का Overview
एक compiler आपके human-readable C source code को processor के actually execute करने लायक machine instructions में translate करता है।
GCC (GNU Compiler Collection) सबसे widely used free compiler है और लगभग हर platform पर available है, cookiescursor.com के अपने Try It tool के अंदर भी।
उदाहरण: Compiler Overview
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("Compiled with GCC into a native executable.");
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Text Editors
कोई भी plain text editor C लिख सकता है, लेकिन coding के लिए बने editors -- VS Code, Vim, या एक IDE -- syntax highlighting और error detection add करते हैं जो compile करने से पहले ही typos पकड़ लेते हैं, बाद के cryptic compiler errors से बचाते हुए।
उदाहरण: Text Editors
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("A good editor highlights syntax errors before you compile.");
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
अपना Code लिखना
Source files को .c extension इस्तेमाल करना होता है ताकि compiler और आपका editor दोनों इन्हें C code पहचानें और सही syntax rules apply करें; गलत extension इस्तेमाल करना एक आम वजह है जिससे compiler किसी file को बिल्कुल build करने से मना कर देता है।
उदाहरण: Writing Your Code
// Save this file as: hello.c
#include <stdio.h>
int main() {
printf("Saved with a .c extension so the compiler recognizes it.");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
अपना Code Compile करना
gcc filename.c -o output चलाना आपकी source file पढ़ता है, इसे syntax errors के लिए check करता है, और अगर यह cleanly compile हो जाए, एक binary executable produce करता है -- यहाँ print होने वाला कोई भी error message उस exact line को point करता है जहाँ compiler confused हुआ।
उदाहरण: Compiling Your Code
// Compile with: gcc hello.c -o hello
#include <stdio.h>
int main() {
printf("Run 'gcc hello.c -o hello' to compile this file.");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Output Run करना
Compiled binary (आमतौर पर Linux/Mac पर a.out या Windows पर filename.exe नाम की) एक standalone program है -- इसे run करना आपके code को सीधे CPU पर execute करता है, उस समय किसी compiler या interpreter की ज़रूरत नहीं होती।
उदाहरण: Running the Output
// After compiling: ./hello (Linux/Mac) or hello.exe (Windows)
#include <stdio.h>
int main() {
printf("This runs as a standalone compiled binary.");
return 0;
}
Login to try C/C++/Java/PHP code in the editor
- Compile करने से पहले file save करना भूल जाना, ताकि compiler पुराना version build कर दे।
.csource file को एक program की तरह run करने की कोशिश करना,./a.outजैसे compiled executable की बजाय।g++से compile करना और C rules की उम्मीद करना, जबकि C++ की तरह compile की गई एक.cfile अलग rules follow करती है।
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