This question already has answers here:
What does "%3d" mean in a printf statement?
(8 answers)
Closed 4 years ago.
can someone explain what the 25 in front of d does in an printf command ?
I have searched the web but don't find a good answer.
e.g.:
printf("%-30s %10lu %25d - %ud\n", "unsigned int", sizeof(unsigned int), 0, UINT_MAX);
Thanks in advance.
%d indicates decimal value.25 total field width.
Related
This question already has answers here:
C/C++ unsigned integer overflow
(4 answers)
Closed 4 years ago.
I was trying to get into c programming, but in a question a get stuck, please explain this.
int main()
{
char c = 255;
c=c+10;
printf("%d",c);
return 0;
}
the output it gave is
> 9
kindly explain this to me.
The maximum value of a char is 255.
By adding 10 to that number you get 265.
Because that value is not a suitable value for a char it will do 265 % 256 resulting 9
That's why your result is 9
This question already has answers here:
What does "%.*s" mean in printf?
(4 answers)
Closed 6 years ago.
Why the following program work ? & what is difference b/w %d vs %*d ?
#include<stdio.h>
int main()
{
int n=5;
printf("n=%*d\n", n, n);
return 0;
}
What does width meant here by ?
The first n belongs to the * in %*d, so for your example it is %5d. %5d means to print an integer of width 5. Example: 234 is printed as __234 (2 spaces)
This question already has answers here:
printf string, variable length item
(2 answers)
Closed 7 years ago.
I need to
printf(%?d)
Where '?' is some int. How can I do it?
I'm using pure c.
I've tried to work with const char* array. But there was no result.
See the printf man page:
int width = 16;
int value = 42;
printf("%*d\n", width, value);
Output:
42
LIVE DEMO
This question already has answers here:
Set variable text column width in printf
(2 answers)
Closed 7 years ago.
I know that I could use printf(%Nd, foo) if N is constant and I know it
But the problem is that N is in variable and calculated in program
I could do it with combining sprintf and printf:
sprintf(formatstr, "%%%dd", N);
printf(formatstr, foo);
But is there any cleaner way?
You can put a * in place of the field width. This means the next parameter will specify the width:
printf("%0*d", size, foo);
This question already has answers here:
What is the "-->" operator in C++?
(29 answers)
Closed 8 years ago.
I have a question, what mean "-->" in C? For example:
int a, b, c, x;
a=2001;
b=1000;
c=2;
x=a-b*c;
printf("First: %i", x-->0);
It will print "1".
But:
printf("Second: %i", x-->0);
will print "0". Why when I use it second time, it print "0"?
x --> 0 is to be read (x--) > 0.
x-->0 is parsed as (x--) > 0.