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
A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles
while initialization of array why we use a[][2] why not a[2][]...?
hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .
What functions are used for dynamic memory allocation in c language?
What is f'n in math?
What is indirection in c?
What is function definition in c?
What is void main () in c?
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
Why does everyone say not to use scanf? What should I use instead?
What is selection sort in c?
Differentiate between static and dynamic modeling.
Can we access the array using a pointer in c language?
Tell me with an example the self-referential structure?
can any one provide me the notes of data structure for ignou cs-62 paper