FORMATE SPECIFIER, CONSTANTS & ESCAPE SEQUENCES IN C
1. FORMATE SPACIFIER :-
* Formate specifier is a way to tell the compiler what type of data is in a variable during taking input displaying output to the user.
* print ("This is a good boy%a.bf",var); will print var with b decimal points in a 'a' character space.
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a = 4;
float b = 4.55;
printf("The value of a is %17d And the value of b is %f", a,b);
return 0;
}
if we use %8f then it gives output by gapping of 8 characters space in forward direction:
if we use %-8d then it gives output by gapping of 8 characters space in backward direction:
But it only work in if print character is less than the given number otherwise it doesn't work:
1. %c --> print character
2. %d --> print integer
3. %f --> print float
4. %l --> print long
5. %lf --> print double
6. %LF --> print Long double
2. CONSTANTS:-
* A constant is a value or variable that that can't be changed in the program, for example : 15,23,'a',3.4,"himanshu.etc".
* There are two ways to define constant in C programming.
--> const keyboard.
--> #defined preprocessor.
#include <stdio.h>
#define PI 3.14
int main(int argc, char const *argv[])
{
int a = 34;
const float b = 45.8;
PI = 23; (this is wrong because 45.8 is a const and it can't change.)
b = 40.9; (this is also wrong because 45.8 is a const and it can't change.)
printf("%f",PI);
return 0;
}
ESCAPE SEQUENCE
* An eascape sequence in C programming language in a scape sequence of characters.
* It doesn't represent itself when used inside string literal or character.
* It is compose of two or more characters starting with backslash \. For ex. \n represents new line.
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a = 2;
float b = 3;
printf("My backslash \\ %d\n", a); // (Backslash print)
printf("tab charcater\t \t my tab char%d",b); // (Tab print)
printf("windows sond \a%f",b); // (For windows sound)
return 0;
}