What does "-->" mean in C? [duplicate] - c

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.

Related

What does %25d mean in C [duplicate]

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.

operations on character pointers [duplicate]

This question already has answers here:
What does 1[d=b] mean?
(3 answers)
Closed 5 years ago.
I came across a code as in below
#include <stdlib.h>
int main(){
char a[]="0123456789";
printf("%s\n",a+6[a]-2[a]);
return 0;
}
Output
456789
How does the calculation of a+6[a]-2[a] happens in printf?
Why giving just 6[a] in printf doesn't work?
printf("%s\n",6[a]);
Well, a statement like
a+6[a]-2[a]
can be re-written as
&(a[ a[6] - a[2] ])
which is simply,
use the value of a[6] (type, int) as the index in the first case
use the value of a[2] (type int) as the RHS.
The result, is a pointer, is passed to printf() as an argument to %s conversion specification.

Format specifier in c [duplicate]

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)

C printf with N leading zeroes [duplicate]

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);

issue with the conditional operator [duplicate]

This question already has answers here:
C conditional operator ('?') with empty second parameter [duplicate]
(6 answers)
Closed 9 years ago.
#include<stdio.h>
int main()
{
printf("%d\n", 4 ?: 8);
}
According to the C standard this program is invalid because it is missing an expression between the ? and :.But The interesting thing is that there is when I compile the code it is printing 4.how come it will print 4 rather than showing any compile error
This is a gcc extension.
x ? : y
is equivalent to
x ? x : y
See here for detail.

Resources