Format specifier in c

Format specifier in c language

This article is all about the format specifier in c language and types of format specifiers, so know about this please read the full article.

There are many types of format specifiers are available in c programming .

The function scanf() and printf() make use of conversion specifications to specify the type and size of data.

And each conversion specification must begin with a percent sign(%).

Various types of format specifier in c language :

%c:

When you are using the %c in your programming that means that the data is a character type data, not an int type data.

And in both the input and output cases we can use the %c .

example:

#include<stdio.h>

#include<conio.h>

void main()

{

char a;

clrscr();

scanf(“%c”,&a);

printf(“output is =%c”,a);

getch();

}

This is an example of %c format specifier.

%d:

This generally means a decimal integer. That means when you want to print the integer value then you can use the %d where you want.

Anything lies inbetween the 0 and 9 stands for decimal integer .

Example:

#include<stdio.h>

#include<conio.h>

void main()

{

int a;

clrscr();

scanf(“%d”&a);

printf(“output is =%d”,a)

}

This is an example of %d of how we use the %d in c programming.

%e:

This is a kind of format specifier or floating point number which we used .

We can use this format specifier in printf as well as in scanf also.

%f:

This is a format specifier and with the help of this format specifier, we mention a floating-point number.

Suppose we have created a variable which is float type such as- float a, so in that place, we can write the %f to display our floating-point integer.

Example:

#include<stdio.h>

#include<conio.h>

void main()

{

float a;

clrscr();

scanf(“%f”,&a);

printf(“output is %f”,a);

getch();

}

This is an example of float and this will holds the floating numbers.

%g:

This is also a format specifier and it is use to print decimal point values.

Mainly this is a floating input output instruction.

Through the help of these we can represent number with float and douhble.

%hu:

There are many types of format specifiers are available and %hu is one of them.

And this is mainly used for the unsigned short integer.

%i:

This is used for several integer values. For decimal, for octal, and for hexadecimal also.

Decimal numbers are built up between any numbers inbetween 0 to 9.

Similarly, hexadecimal numbers are built from 0 to 9 and 10 is represents as a and this process will continue.

Octals are the numbers that are built in between 0 to 7.

%lf:

This is one of the most useable format specifier in c language.

We can use this for long range or for floating point number.

This is normally used with the double data type.

And if you use the capital LF then that is used for long data double.

%hu:

It is used for the short or for unsigned.

%o:

This is a format specifier which we use with an octal integer

%p:

It is use for an address or for pointer.

%S:

This is use for the strings in programming.

And strings are always written with in the double quotes.

%u:

We use this for the unsigned decimal integer. We can also use this for the address.

This will use in the pointers. So if you want to use the unsigned integer then you can easily use this specifier.

%x:

This is a format specifier use for the hexadecimal integer value.

%n:

It is a spcefier which prints nothing.

%%:

This is also a format specifier which is used for % symbol.

Conclusion:

Here in this article, we mention the various format specifier in the c language.

If you want to learn computer programming then please follow our website and here we will update lots of informational content.

Also read

Escape sequences in c language
Keywords in c programming
Variables in c language
Operators in c language
Best youtube channel to learn c programming