C - SPLessons

Chapter 13

Printf C

Printf C

“Printf C” chapter gives clear description about how to take input and give output and various format specifiers used.

Any language will be finally used to input/output the data from/to the user which shows its success rate. C-language also has input and output functions for taking the data and returning the data from a program. This action requires keyboard for inputting and monitor screen for outputting. As soon as the program starts, compiler gives access to the those devices by using:


Input in C-language can be given using “scanf() function. scanf() function requires access over the address of the value entered.

& is used for locating the address of the given input. It takes the input form stdin. To read any character, scanf() takes the help of format specifiers.

In the below example, compiler asks to enter a number and scans it.

int main()
	int a;
	printf("Enter a number ");


Enter a number 5


Output in C-language can be given by using “printf() function. printf() returns the characters taken by it. printf() C function supports two type of characters. The characters need to be placed within the quotes( ” ” ).

int main(void)
	printf("Welcome to splessons");
	return 0;


Welcome to splessons

Format specifiers

Format Specifier Description Supported data types
%d Signed integerint short,unsigned short,int,long
%hi Signed integer(short) short
%hu Unsigned integer(short) unsigned short
%i Signed integer(short) short,unsigned short,int,long
%l or %ld or %li Signed integer long
%lu Unsigned integer unsigned int, unsigned long
%u Unsigned integer(short) unsigned int, unsigned long
%lli,%lld Signed integer(short) long long
%llu Unsigned integer(short) unsigned long long
%o Octal representation of integer(short) short,unsigned short,int,unsigned int,long
%x oor %X Hexadecimal representation of Unsigned integer(short) short,unsigned short,int,unsigned int,long
%c Character char,unsigned char
%p Address of pointer to void void* void*
%s String char*
%e or %E Scientific notatiom of float values float,double
%f Floating point float
%g or %G Similar as %e or %E float,double
%lf Floating point double
%Lf Floating point long double
%n Prints nothing
%% Prints % character


“Printf C” chapter draws out following main points.

  • printf() C function is used to print the output.
  • scanf() function reads the input given.
  • Format specifiers helps in finding the inputted data type.