C के Escape Sequences
In this page:
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?
// 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;
}
Login to try C/C++/Java/PHP code in the editor
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 ( )
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Quotes Print करना (" और \')
क्योंकि C strings double quotes से delimited होते हैं, इसके अंदर एक literal " लिखना string को जल्दी खत्म कर देगा और compiler को confuse कर देगा -- \" compiler को उस character को delimiter की बजाय literal text की तरह treat करने को कहता है।
उदाहरण: Printing Quotes (" and \')
// 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;
}
Login to try C/C++/Java/PHP code in the editor
एक Backslash Print करना (\)
क्योंकि backslash खुद हर escape sequence शुरू करता है, एक actual backslash character print करने के लिए लगातार दो लिखने होते हैं (\\) -- पहला backslash दूसरे को escape करता है, compiler को बताते हुए कि आपका मतलब literally वह character है।
उदाहरण: Printing a Backslash (\)
// 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;
}
Login to try C/C++/Java/PHP code in the editor
Audible Alert Bell (\a)
\a एक visible character print करने की बजाय terminal की audible alert sound produce करता है (अगर terminal इसे support करे) -- historically user का ध्यान खींचने के लिए इस्तेमाल होता था, हालांकि modern interfaces में इस पर शायद ही कभी भरोसा किया जाता है।
उदाहरण: Audible Alert Bell (\a)
// 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;
}
Login to try C/C++/Java/PHP code in the editor
"C:\new\test"जैसा एक Windows path लिखना, जहाँ\nऔर\tएक newline और एक tab बन जाते हैं; हर backslash को\\लिखना होगा।- एक string के अंदर एक double quote को
\"की तरह escape किए बिना डालना, जो string को जल्दी खत्म कर देता है और code तोड़ देता है। - एक नई line के लिए
\nकी बजाय/nलिखना, जो सिर्फ एक slash और letter n print करता है।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: