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.
- C++ final specifier
- Can we access global variable if there is a local variable with same name?
- 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
- C++ program to convert time from 12 hour to 24 hour format
- Structures in C++
- Variables in C++
- Implementing Forward Iterator in BST
- Count substrings that contain all vowels | SET 2
- Machine Learning in C++