Skip to main content

C Format Specifiers

·         C Tutorial
·          
·         C Format Specifiers

Format specifiers can be defined as the operators which are used in association with printf() function for printing the data that is referred by any object or any variable. When a value is stored within a particular variable then you cannot print the value stored in the variable straightforwardly without using the format specifiers. You can retrieve the data that are stored in the variables and can print them onto the console screen by implementing these format specifiers in a printf() function.
Format specifiers start with a percentage % operator and followed by a special character for identifying the type of the data.
There are mostly 6 types of format specifiers that are available in C.
List of format specifiers in C
Format specifier
Description
%d
Integer Format Specifier
%f
Float Format Specifier
%c
Character Format Specifier
%s
String Format Specifier
%u
Unsigned Integer Format Specifier
%ld
Long Int Format Specifier
Integer Format Specifier %d
The %d format specifier is implemented for representing integer values. This is used with printf() function for printing the integer value stored in the variable.
Syntax:
printf("%d",<variable name>);
Float Format Specifier %f
The %f format specifier is implemented for representing fractional values. This is implemented within printf() function for printing the fractional or floating value stored in the variable. Whenever you need to print any fractional or floating data, you have to use %f format specifier.
Syntax:
printf("%f", <variable name>);
Character Format Specifier %c
The %c format specifier is implemented for representing characters. This is used with printf() function for printing the character stored in a variable. When you want to print a character data, you should incorporate the %c format specifier.
Syntax:
printf("%c",<variable name>);
String Format Specifier %s
The %s format specifier is implemented for representing strings. This is used in printf() function for printing a string stored in the character array variable. When you have to print a string, you should implement the %s format specifier.
Syntax:
printf("%s",<variable name>);
Unsigned Integer Format Specifier %u
The %u format specifier is implemented for fetching values from address of a variable having unsigned decimal integer stored in the memory. This is used within printf() function for printing the unsigned integer variable.
Syntax:
printf("%u",<variable name>);
Long Int Format Specifier %ld
The %ld format specifier is implemented for representing long integer values. This is implemented with printf() function for printing the long integer value stored in the variable.
Syntax:

printf("%ld",<variable name>);

Comments

For Programs Click Here

Popular posts from this blog

Python Lists

Python Lists Dealing with data in a structured format is quiet generous, and this is possible if those data are set accordingly in a specific manner. So, Python provides these data structures named ‘lists’ and ‘tuples’ that are used to organize data in  single set. Python has 6 built-in sequences and among them the most famous are “lists and tuples”. The lists are containers that hold a number of other objects in a given order. It usually puts into practice the sequence protocol and allows programmers to add or remove objects from that sequence. Each element of the sequence is assigned a number i.e. he index and the first index is 0 (zero). This versatile data-type of Python is written in a sequence of list separated by commas between expressions. Creating Lists To build a list, just put a number of expressions in square brackets. The syntax is: Syntax: lst1 = [ ] # lst1 is the name of the list lst2 = [ expression1 , …. , expression_N ] Example: #!/usr/bin/python ls...

C++ Qualifiers and Storage Classes

C++ Qualifiers and Storage Classes Qualifiers and storage class are smaller but important programming concept that helps to make the quality of a variable more accurate for using that variable within the program. In this chapter you will learn about how qualifiers are used with variables and what the roles of different storage classes in C++ are. What is a Qualifier? A qualifier is a token added to a variable which adds an extra  quality , such as specifying volatility or constant-ness to a variable. They act like an adjective for a variable. With or without a qualifier, the variable itself still occupies the same amount of memory, and each bit has the same interpretation or contribution to the state/value. Qualifiers just specify something about how it may be accessed or where it is stored. Three qualifiers are there in C++. These are: const : This is used to define that the type is constant. volatile : his is used to define that the type is volatile. mutable:  applies to non...

C++ if-else Statements

C++ if-else Statements If else statements in C++ is also used to control the program flow based on some condition, only the difference is: it’s used to execute some statement code block if expression is evaluated to true, otherwise executes else statement code block. The basic format of if else statement is: Syntax: if ( test_expression ) { //execute your code } else { //execute your code } Figure – Flowchart of if else Statement: Example of a C++ Program to Demonstrate if else Statement Example: #include <iostream> using namespace std ; int main () { int a = 15 , b = 20 ; if ( b > a ) {    cout << "b is greater" << endl ; } else {    cout << "a is greater" << endl ; }    system ( "PAUSE" ); } Program Output: Example: #include <iostream> using namespace std ; int main () { char name ; int password ; cout << "Enter the name: " ; cin >>...