Escape Sequence In Dev C%2b%2b
When a character is preceded by a backslash ( ), it is called an escape sequence and it has a special meaning to the compiler. For example, in the following statement is a valid character and it is called a new line character − char ch = ' '.
Two basic topics that every programmer in C should be familiar with is Format specifier and Escape sequences. Escape sequences allow the user to access certain functionalities that are not available otherwise. Format specifiers are used for working on various data types.
Output: (Depend upon compiler) Hello GFG Explanation: It contains two escape sequence means it after printing the the compiler read the next as as new line character i.e., which print the GFG in the next line. C treats as an escape code. Here’s an interesting and almost useless fact: escape does not mean “get out”, not when referring to and not even when referring to the top left-hand key on the keyboard. In 2016, Microsoft released the Windows 10 Version 1511 update which unexpectedly implemented support for ANSI escape sequences. The change was designed to complement the Windows Subsystem for Linux, adding to the Windows Console Host used by Command Prompt support for character escape codes used by terminal-based software for Unix-like systems.
Escape Sequences
Escape sequences are a sequence of characters that represent a different meaning when used in a string literal. Escape sequences are the same for many other programming languages like java, c++, c#, etc. They usually begin with the ‘(backslash)’ symbol. Here is a list of escape sequences:
ESCAPE SEQUENCES | DESCRIPTION |
---|---|
a | alarm or beep or bell |
b | backspace |
f | Form feed |
n | New Line |
r | Carraige Return (reset the device’s position to the beginning of a line) |
t | Horizontal Tab |
v | Vertical Tab |
Backslash | |
’ | Single Quote |
” | Double Quote |
? | Question Mark(used to avoid trigraphs) |
nnn | Interpreted as an Octal Number |
xhh | Interpreted as a Hexadecimal Number |
0 | Null |
e | Escape character |
Uhhhhhhhh | Unicode code point. H is a hexadecimal digit |
uhhhh | Unicode code point below 10000 hex. |
Note: There are some non-standard or invalid escape sequences like z that needs to be diagnosed, i.e the compiler will print an error message.
Format Specifiers
Format specifiers basically help us work with different types of data types. Format specifiers are generally used during standard input and standard output procedures in C programming Language also referred to as formatted input and formatted output. C does not allow the user to print or input the values straightforward. The programmer must make use of the format specifiers. For example:
Format specifiers are preceded by a ‘%’ sign. Here is a list of the format specifiers available in C Programming language.
FORMAT SPECIFIERS | DESCRIPTION |
---|---|
%d or %i | Signed Integer. Supports short, unsigned short, int and long. |
%hi | Signed Integer. Supports short. |
%hu | Unsigned Integer. Supports Unsigned short. |
%l or %ld or %li | Signed Integer. Supports long. |
%lu | Unsigned Integer. Supports unsigned int and unsigned long. |
%lli or %lld | Signed Integer. Supports long long. |
%llu | Unsigned Integer. Supports unsigned long long. |
%o | Octal of an Integer. Supports short, unsigned short, int, unsigned int and long. |
%u | Unsigned integer. Supports unsigned int and unsigned long. |
%x or %X | Hexadecimal of Unsigned Integer. Supports short, unsigned short, int, unsigned int and long. |
%e or %E or %g or %G | Scientific notation of float values. Supports float and double. |
%f | Floating point(float). |
%lf | Floating point(double). |
%Lf | Floating point(long double). |
%c | Character. Supports char and unsigned char. |
%s | String(char *). |
%p | Pointer address to void(void *). |
%n | Null value(prints nothing). |
%% | Prints % character. |
Note: Format specifiers are also known as format strings.
Keep Coding!! Happy Coding!! 🙂
Knowledge is most useful when liberated and shared. Share this to motivate us to keep writing such online tutorials for free and do comment if anything is missing or wrong or you need any kind of help.
Escape Sequence In Dev C 2b 2b 1
Do not forget to share and Subscribe.
Keep Learning… Happy Learning… 🙂