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
in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
What is register variable in c language?
What are # preprocessor operator in c?
What is the use of ?
Explain what is the benefit of using an enum rather than a #define constant?
What is echo in c programming?
which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;
What functions are in conio h?
What is static and auto variables in c?
What is pointer in c?
Is it possible to have a function as a parameter in another function?
Explain what is wrong with this program statement?
int far *near * p; means
Which is the best website to learn c programming?