← Back to C Course | Chapter 2: Input & Output | Lesson 5 of 7

C के Escape Sequences

Escape sequences text के अंदर special two-character codes हैं जो new line या tab जैसी चीज़ों के लिए खड़े होते हैं, secret shortcuts की तरह। Backslash C को बताता है 'अगला letter special है'।
Syntax
c
printf("first\tsecond\nnew line\\ backslash \"quote\"");

Escape Sequences क्या हैं?

एक escape sequence backslash से शुरू होने वाला एक two-character combination है जो एक ऐसे character को represent करता है जिसे आप एक string literal में सीधे type नहीं कर सकते -- जैसे एक line break, एक tab, या वह quote character जिसे string खुद अपने delimiter के तौर पर इस्तेमाल करता है।

उदाहरण: What are Escape Sequences?

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Print formatted text to the screen
	printf("Tab:\tNewline:\n");
	// Return 0 to signal that the program finished successfully
	return 0;
}

Newline (\n) और Horizontal Tab (\t)

\n cursor को अगली line की शुरुआत में ले जाता है और C में output lines खत्म करने का standard तरीका है, जबकि \t एक tab-width space insert करता है, printed output में text के columns को align करने के लिए useful।

उदाहरण: Newline ( ) and Horizontal Tab ( )

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Print formatted text to the screen
	printf("Name:\tAge\nAlice:\t30");
	// Return 0 to signal that the program finished successfully
	return 0;
}

Quotes Print करना (" और \')

क्योंकि C strings double quotes से delimited होते हैं, इसके अंदर एक literal " लिखना string को जल्दी खत्म कर देगा और compiler को confuse कर देगा -- \" compiler को उस character को delimiter की बजाय literal text की तरह treat करने को कहता है।

उदाहरण: Printing Quotes (" and \')

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Print formatted text to the screen
	printf("She said \"hello\"");
	// Return 0 to signal that the program finished successfully
	return 0;
}

एक Backslash Print करना (\)

क्योंकि backslash खुद हर escape sequence शुरू करता है, एक actual backslash character print करने के लिए लगातार दो लिखने होते हैं (\\) -- पहला backslash दूसरे को escape करता है, compiler को बताते हुए कि आपका मतलब literally वह character है।

उदाहरण: Printing a Backslash (\)

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Print formatted text to the screen
	printf("Path: C:\\folder");
	// Return 0 to signal that the program finished successfully
	return 0;
}

Audible Alert Bell (\a)

\a एक visible character print करने की बजाय terminal की audible alert sound produce करता है (अगर terminal इसे support करे) -- historically user का ध्यान खींचने के लिए इस्तेमाल होता था, हालांकि modern interfaces में इस पर शायद ही कभी भरोसा किया जाता है।

उदाहरण: Audible Alert Bell (\a)

c
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Program execution starts in main()
int main() {
	// Print formatted text to the screen
	printf("Alert\a");
	// Return 0 to signal that the program finished successfully
	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. "C:\new\test" जैसा एक Windows path लिखना, जहाँ \n और \t एक newline और एक tab बन जाते हैं; हर backslash को \\ लिखना होगा।
  2. एक string के अंदर एक double quote को \" की तरह escape किए बिना डालना, जो string को जल्दी खत्म कर देता है और code तोड़ देता है।
  3. एक नई line के लिए \n की बजाय /n लिखना, जो सिर्फ एक slash और letter n print करता है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

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.