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 pointer & why it is used?
what is reason of your company position's in india no. 1.
What is hash table in c?
What is the best way to store flag values in a program?
What does c mean before a date?
Does c have class?
What is the difference between text files and binary files?
What is the purpose of type declarations?
What is clrscr in c?
Explain what is the concatenation operator?
Explain 'far' and 'near' pointers in c.
What are the benefits of c language?
Difference between constant pointer and pointer to a constant.
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
What is the use of bitwise operator?