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

What is pointer & why it is used?

1063


what is reason of your company position's in india no. 1.

2237


What is hash table in c?

976


What is the best way to store flag values in a program?

1012


What does c mean before a date?

1109


Does c have class?

1054


What is the difference between text files and binary files?

1285


What is the purpose of type declarations?

1079


What is clrscr in c?

1078


Explain what is the concatenation operator?

1111


Explain 'far' and 'near' pointers in c.

1084


What are the benefits of c language?

1112


Difference between constant pointer and pointer to a constant.

1069


Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.

1071


What is the use of bitwise operator?

1070