Kp Solutions  India
Excellence Software Engineering & Research Centre

printf() function

Thursday, July 14, 2011

printf() function

you will think that printf() is simple function and WHAT TO LEARN ABOUT IT ?

Today we will going to learn some facts of printf() which you sometimes ignored.

printf() is standard inbuilt function of C programming language defined in header file. It is used to perform output operation on output screen i.e. It is used to print data on output screen, data includes string, character, integer number, floating number etc.

Let us check your knowledge, please try to answer following program.
Find output of following program.

Example 1:
#include
main()
{
printf("Value=%d",printf("Hello"));
}

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Output of this program is

==> HelloValue=5

Let us learn the core concept of printf() function.

syntax :

int printf(const char *format, ...);


printf() function prints the data on output screen as per the given format.
Upon successful operation of printf(), these functions returns the number of
characters printed on output screen and therefore its return type is int.
In the above example, inner printf() function prints "Hello" on output screen
and returns 5 (length of "Hello" string) to outer printf() function and therefore outer printf function gets value 5 in place of %d format specifier.

Try more examples :

Example 2:

#include
main()
{
int n=100;
printf("Value=%d",printf("Value=%d",n));
}

output : Value=100Value=9

Example 3:

#include
main()
{
int n=10;
printf("Value=%d",printf("Value=%d",n));
}
output : Value=10Value=8



Best of Luck - Try to learn the unknown things.


http://ifinc.blogspot.in

http://sizeofinc.blogspot.in/

http://e-testseries2012.blogspot.in/

http://engineerscollegeview.blogspot.in/

http://googlecrashed.blogspot.in/

http://kpsolutionsindia-softwarestatistics.blogspot.in/

http://kpsolutionsindia.blogspot.in/

http://clanguagebykp.blogspot.in/

Copyright 2017 KP Solutions. All Rights Reserved.