Format Specifiers in C
×


Format Specifiers in C

153

 In C programming, a format specifier is like a special code used in functions such as printf, and scanf() to instruct the program on how to format the data you're working with.

 For Example, if you want to print a number, you use '%d' as the format specifier with printf.

 Likewise, when you want to read input with scanf, you use format specifiers to tell the program what type of data to expect.

Commonly Used Format Specifiers

 '%d' Printing or Scanning Integers they are whole numbers.

 '%f' For Printing or Scanning Floating Point numbers they are decimal numbers.

 '%c' represents a Single Character.

 '%s' represents a String.

 '%x'/'%X' Outputs Hexadecimal Numbers in lowercase and uppercase.

 '%p' print or scan Memory Addresses(pointers).

 '%u' is the Unsigned Integer.

Example:

#include<stdio.h>
int main()
{
int i = 10;
float f = 3.8;
char c = 'R';

printf("integer:%d\n", n);
printf("float:%f\n", p);
printf("character:%c", ch);

return 0;
}
In this example,

%d is used to print the integer variable n.

 %f is used to print the float variable point.

 %c is utilized to display the character stored in the variable ch.

Output:

integer: 10
float: 3.8000
character: R


Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments