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 typedef struct in c?
What is dynamic variable in c?
‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .
How can I call fortran?
How can I find out the size of a file, prior to reading it in?
int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer
Why c is known as a mother language?
Tell me with an example the self-referential structure?
How many types of arrays are there in c?
What is a pointer variable in c language?
Which built-in library function can be used to match a patter from the string?
What are keywords c?
What does volatile do?
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
How can I do peek and poke in c?