Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ( ) in printf argument list. What does this syntax mean?

Tags:

c

I run into a code:
printf("\tout:\t%-14.14s\n", (sprintf(tmpbuf[0], "[%s]", mystring), tmpbuf[0]));
What does those sentence in () with sprintf mean?

like image 803
hasnobrains Avatar asked Oct 05 '12 12:10

hasnobrains


Video Answer


1 Answers

It is an expression involving the comma operator, to put the following into a single line:

sprintf(tmpbuf[0], "[%s]", mystring);
printf("\tout:\t%-14.14s\n", tmpbuf[0]);

The comma operator evaluates both arguments and returns its right argument, i.e. tmpbuf[0].

like image 131
Andrey Avatar answered Oct 21 '22 21:10

Andrey