%i Format Specifier
About %i Format Specifier :
Here, in this page we will discuss about the %i format specifier in C. They are used to take input and print output of different type. %i is one of the format specifier.
%i Format Specifier :
- %i is a format specifier used to take input in scanf and print output in printf as integer. % is used before any format specifier to check which data type is used.
- %i takes integer value as integer value with decimal, hexadecimal or octal type.
- %i behave differently in printf and scanf function of the program.
Examples of %i Format Specifier :
Let,s see some example for better understanding :
Example 1:
Run
#include<stdio.h> int main() { int val =25; printf("The value given is : %i", val); return 0; }
Output :
The value given is : 25
What Happened Above?
In the program, we take the value val 25 and %i is used in the printf function to print the integer.
Example 2 :
Run
#include<stdio.h> int main() { int val =25; float val2 = 25.1; printf("The value given is : %i\n", val); printf("The value given in flaot is : %f", val2); return 0; }
Output :
The value given is : 25 The value given in flaot is : 25.100000
What Happened Above?
In the program, we take the value val 25 as integer and val2 25.1 as float , %i is used for the integer and %f is used for the float to print the value.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
How to write test in this website