Escape Sequence in C

An escape sequence in C language is a sequence of characters that doesn't represent itself when used inside string but has diffrent meaning as below.

List of Escape Sequences in C

Escape SequenceMeaning
\aAlarm or Beep
\bBackspace
\fForm Feed
\nNew Line
\rCarriage Return
\tTab (Horizontal)
\vVertical Tab
\\Backslash
\'Single Quote
\"Double Quote
\?Question Mark
\nnnoctal number
\xhhhexadecimal number
\0Null

Escape Sequence Example:

#include <stdio.h>      
void main( ) {      
int number = 60;         
printf("You\nare\nmy\n\'best\'\nfriend\n\"catchmecoder\"");       
}      
Output:
You
are
my
'best' 
friend
"catchmecoder"

Constants in C

A constant is a value or variable that can't be changed in the program, for example: 10, 20, 'a', 3.4, "c programming" etc.
There are different types of constants in C programming

List of Constants in C

ConstantExample
Decimal Constant10, 20, 450 etc.
Real or Floating-point Constant10.3, 20.2, 450.6 etc.
Octal Constant021, 033, 046 etc.
Hexadecimal Constant0x2a, 0x7b, 0xaa etc.
Character Constant'a', 'b', 'x' etc.
String Constant"c", "c program", "c in catchmecoder" etc.

2 ways to define constant in C

There are two ways to define constant in C programming.
  • const keyword
  • #define preprocessor
  • C constant keyword

    The const keyword is used to define constant in C programming.

    const float PI = 3.14;
    Now, the value of PI variable can't be changed.
    #include <stdio.h>  
    void main( ) {      
    const float PI = 3.14;       
    printf("The value of PI is: %f",PI);   
      }      
    Output:
    The value of PI is: 3.140000

    C #define preprocessor

    The #define preprocessor is also used to define constant. we will learn later.
    Visit here for: to know more # define preprocessor.