what is the difference between %d and %*d in c languaga?
Answer Posted / shivam chaurasia
The %*d in a printf allows you to use a variable to control the field width, along the lines of:
int wid = 4;
printf ("%*d
", wid, 42);
output,...
..42
if the form is like this...
printf ("%*d %*d
", a, b);
is undefined behaviour as per the standard, since you should be providing four arguments after the format string, not two (and good compilers like gcc will tell you about this if you bump up the warning level). From C11 7.20.6 Formatted input/output functions:
If there are insufficient arguments for the format, the behavior is undefined.
It should be something like:
printf ("%*d %*d
", 4, a, 4, b);
check this link for extra detail....
http://www.cplusplus.com/reference/cstdio/printf/
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is pivot in c?
How can I find out if there are characters available for reading?
Differentiate between a structure and a union.
What are the usage of pointer in c?
Read the following data in two different files File A: aaaaaaaadddddddd bbbbbbbbeeeeeeee ccccccccffffffff File B: 11111111 22222222 33333333 By using the above files print the following output or write it in the Other file as follows aaaaaaaa11111111dddddddd bbbbbbbb22222222eeeeeeee cccccccc33333333ffffffffffff
explain what is a newline escape sequence?
What is an example of structure?
What Is The Difference Between Null And Void Pointer?
Explain union.
How can this be legal c?
What are multidimensional arrays?
how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions
What is the process to create increment and decrement stamen in c?
What is c method?
write a program to find out prime number using sieve case?