It is known that, printf() function is an inbuilt library function in C programming language in the header file stdio.h. It is used to print a character, string, float, integer etc. onto the output screen. However, while printing the float values, the number of digits following the decimal point can be controlled by the user. One of the ways to do that is by using formats like %.2f etc. But variables can also be used for formatting format specifiers.
Below example shows how this can be done.
This article is contributed by MAZHAR IMAM KHAN. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Can we access global variable if there is a local variable with same name?
- C++ final specifier
- Understanding constexpr specifier in C++
- Format specifiers in C
- Different ways to initialize a variable in C/C++
- Variable Length Arrays in C and C++
- Different ways to declare variable as constant in C and C++
- Set a variable without using Arithmetic, Relational or Conditional Operator
- Program to convert time from 12 hour to 24 hour format
- Conditional or Ternary Operator (?:) in C/C++
- forward_list insert_after() function in C++ STL
- Count of distinct remainders when N is divided by all the numbers from the range [1, N]
- Formatted I/O in C++
- C++ | asm declaration