top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

What is the difference between %d and %*d in c language?

+5 votes
What is the difference between %d and %*d in c language?
posted Dec 4, 2013 by Anuj Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

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\n", wid, 42);

which will give you:


(with each of those . characters being a space). The * consumes one argument wid and the d consumes the 42)

answer Dec 4, 2013 by Alok Kumar
Nice explanation...
0 votes

%d gives the original value of the variable and %*d gives the address of the variable.


int a=10,b=20;

Result is
10 20
1775 1775

Here 1775 is the starting address of the memory allocation for the integer. a and b having same address because of contagious memory allocation.

answer Dec 8, 2013 by Neeraj Pandey
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.