cznomad.blogg.se

How to use printf in c programming
How to use printf in c programming













how to use printf in c programming

Similarly, while using printf(), we often see use of \t and \n frequently. We can control this behaviour by using %0.2f, this tells compiler to print only two digit after decimal point. And by default when using %f, six digit after decimal point is printed. After that in printf() statement everything is printed as it is but in place of %d value of a is assigned since %d is placeholder for integer and in place of %f value of b is assigned since %f is placeholder for floating number. Then we assigned value 2 to variable a and value 4.5 to variable b. In the above program, we first declared variable a as integer using int and b as floating or fractional number using float. Printf("Value of a = %d and b = %f.", a, b) Example #2 : Format Specifier ( % ) in printf() Think of format specifier as a placeholder for some variable. In those situation we use format specifier that starts with % sign. While programming, we often come to situation in which we need to print value of variable. Once stdio.h is included then we can use all the function that are defined in this header file. So to use printf() in our program we must include stdio.h using #include directive. Here, header file stdio.h is included because the prorotype of function printf() is defined in this library. This statement simply prints Welcome to the world of C programming to the standard output unit. When we want to display some text or string to standard output unit then we can use printf() as printf("Welcome to the world of C programming"). The arguments must match in n umber, order and type with the format specifications. The arguments var1, var2, …, varN are the variables whose values are formatted and printed according to format specifications of the format string.

how to use printf in c programming

The format string indicates how many arguments follow and what their types are. Escape sequences that begin with \ sign.

how to use printf in c programming

Format specifier that begin with a % sign.Characters that are simply printed as they are.Printf(“format_string”, var1, var2, var3, …, varN) So, to use printf(), we must include header file stdio.h in our program. It is defined in standard header file stdio.h. Printf() is formatted output function which is used to display some information on standard output unit.















How to use printf in c programming