Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles

1163


while initialization of array why we use a[][2] why not a[2][]...?

2342


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 .

2426


What functions are used for dynamic memory allocation in c language?

1133


What is f'n in math?

1051


What is indirection in c?

1056


What is function definition in c?

1067


What is void main () in c?

1185


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

1003


Why does everyone say not to use scanf? What should I use instead?

1412


What is selection sort in c?

1064


Differentiate between static and dynamic modeling.

1082


Can we access the array using a pointer in c language?

1031


Tell me with an example the self-referential structure?

1000


can any one provide me the notes of data structure for ignou cs-62 paper

2163