Format specifier and Escape sequences

Format specifier

~ It is the way to tell the compiler what data type is in a variable during taking input displaying output to user.
~ printf("This is a good boy %a.bf",var); will print var with b decimal points in a 'a' character space.

note: It will always be👇
int a = 4;  |(%d)
float b = 3.3;  |(%f)

move on to code:👇
#include <stdio.h>
int main()
{
    int a = 8;
    float b = 7.333;

     printf("hello world");
     printf(" the value of a is %d and the value of b is %0.3f\n"a,b);
    return 0;
}

if  in [printf("%10.4f", b);] it means it will gives the b decimal points accuracy (it will takes 10 character's space) where as [-10.4] will gives the output reverse.

Important format specifiers

%c = char
%d = int
%f = float
%l = long
%lf = double
%LF = long double

Constants

A constant is a value which we can not be changed.
There are two ways in C to define a constant:👇
    Const keyword
    # define preprocessor

Const keyword 

code👇
#include <stdio.h>
int main()
{
    int a = 8;
    const float b = 7.333;
    b = 7.22;

Here the const keyword makes the vale of the float value is constant, now the value of b can't be changed.

Define preprocessor

code👇
#include <stdio.h>
#define PI 3.14
int main()
{
    int a = 8;
    float b = 7.333;
    PI = 23.98; | //you cant do this bcz PI is already defined as a constant

Here the value of PI is already given before starting the main programe, so it can't be changed again in during the main programming.

Escape sequences

An escape sequence in C is a sequence of characters, It doesn't represent itself when used inside string litral or character, It is composed of two or more characters starting with backslash (\).
Ex👉   \n  is used for a new line character.

List of some scape sequences in C👇

Escape Sequences

Meanings

\a

Alarm or beep

\b

Backspace

\f

Form feed

\n

New line

\r

Carriage return

\t

Horizontal tab

\v

Vertical tab

\\

Backslash

\’

Single quote

\’’

Double quote

\?

Question mark

\nnn

Octal number

\xhh

Hexadecimal number

\0

Null

 Comments

Comments is genrally gives you the knowledge to know about the tokens or building block work, comments will never be recognised by the main program, it will be genrally ignored.
 
👇
#include <stdio.h>
int main()
{
// This is a single line comment

/*
This is 
a multiline 
comment
*/
    return 0;
}

Comments

Popular Posts