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 do you mean by keywords in c?
What are inbuilt functions in c?
Can you assign a different address to an array tag?
write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...
How do you generate random numbers in C?
What is c basic?
find out largest elemant of diagonalmatrix
What are multidimensional arrays?
How many types of operators are there in c?
How can I swap two values without using a temporary?
List the difference between a While & Do While loops?
What are the benefits of organizational structure?
Why do we use int main?
What is the basic structure of c?
What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }