Constants

  • Constants are identifiers that represent fixed values
  • when we have to keep an variable unchange through out  the
    the program then we use constants
  • it can done by  using the "const" keyword
    • Syntax: const data-type constant_name = value;
    • Ex: const float pi = 3.14;
  • another method is using macros, macros we will be studying  deeply in further modules.
    • Syntax: #define constant_name = value;
    • Ex: #define pi = 3.14;

lets see by one simple program

#include<stdio.h>
#define pi 3.14        //macros substitution
const float pi1 = 2.48;     //declaration through constant keyword

main(){

printf("constant value declaration through constant keyword is %f",pi1);

printf("\nconstant value through macros declaration is %f",pi);
}

Output:

constant value declaration through constant keyword is 2.48
constant value through macros declaration is 3.14

Escape Sequence in C



Escape sequences are used in the programming languages C and C++, and their design was copied in many other languages such as Java and C#. An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is translated into another character or a sequence of characters that may be difficult or impossible to represent directly. In C, all escape sequences consist of two or more characters, the first of which is the backslash, \ (called the "Escape character"); the remaining characters determine the interpretation of the escape sequence. For example, \n is an escape sequence that denotes a newline character.
Escape sequence are very usefull.
Constant Meaning
\t Insert the tab in the next at this point
\b Insert the backspace in the next at this point
\n Insert the newline in the next at this point
\r Insert the carriage return in the next at this point
\f Insert the formatted in the text at this point
\' Insert the quote in the text at this point
\" Insert the double quote character in the text at this point
\\ Insert the backslash character in the text at this point



below are the example of escape sequences


1
2
3
#include<Stdio.h>        // header file
  
printf("HelloWorld");         // prints the message hello world 



Output:

HelloWorld



Printing Message with Space With the Help Of Escape Sequence:"\t"


#include<Stdio.h>        // header file
  
printf("Hello\tWorld");         // prints the message hello  world 



Output:

Hello         World






Print the Message hello world in which "world" is print in the next line.
Escape Sequence:"\n"






#include<Stdio.h>        // header file
  
printf("Hello\nWorld");         // prints the message hello world 



Output:

Hello
World





#include<Stdio.h>       // header file
  
printf("\"HelloWorld\"");         // prints the message hello world with quotes 



Output:

"HelloWorld"





Remaining one's you can try by yourself




People Also Searched: