← Back to C Course | Chapter 1: Introduction & Basics | Lesson 3 of 21

C Environment का Setup

C setup करना अपनी workshop तैयार करने जैसा है: आप एक compiler install करते हैं जो आपकी instructions को एक program में बदलता है, अपना code लिखते हैं, और result run करते हैं।

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

c
// 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;
}

Text Editors

कोई भी plain text editor C लिख सकता है, लेकिन coding के लिए बने editors -- VS Code, Vim, या एक IDE -- syntax highlighting और error detection add करते हैं जो compile करने से पहले ही typos पकड़ लेते हैं, बाद के cryptic compiler errors से बचाते हुए।

उदाहरण: Text Editors

c
// 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;
}

अपना Code लिखना

Source files को .c extension इस्तेमाल करना होता है ताकि compiler और आपका editor दोनों इन्हें C code पहचानें और सही syntax rules apply करें; गलत extension इस्तेमाल करना एक आम वजह है जिससे compiler किसी file को बिल्कुल build करने से मना कर देता है।

उदाहरण: Writing Your Code

c
// Save this file as: hello.c
#include <stdio.h>
int main() {
	printf("Saved with a .c extension so the compiler recognizes it.");
	return 0;
}

अपना 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

c
// 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;
}

Output Run करना

Compiled binary (आमतौर पर Linux/Mac पर a.out या Windows पर filename.exe नाम की) एक standalone program है -- इसे run करना आपके code को सीधे CPU पर execute करता है, उस समय किसी compiler या interpreter की ज़रूरत नहीं होती।

उदाहरण: Running the Output

c
// After compiling: ./hello  (Linux/Mac) or hello.exe (Windows)
#include <stdio.h>
int main() {
	printf("This runs as a standalone compiled binary.");
	return 0;
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. Compile करने से पहले file save करना भूल जाना, ताकि compiler पुराना version build कर दे।
  2. .c source file को एक program की तरह run करने की कोशिश करना, ./a.out जैसे compiled executable की बजाय।
  3. g++ से compile करना और C rules की उम्मीद करना, जबकि C++ की तरह compile की गई एक .c file अलग rules follow करती है।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.