printf作为函数的参数

Bdf*_*dfy 3 c printf arguments function argument-passing

通常使用功能:

my_func("test");
Run Code Online (Sandbox Code Playgroud)

我是否可以使用这个参数呢?

my_func(printf("current_count_%d",ad_id));
Run Code Online (Sandbox Code Playgroud)

int my_func(const char*key)

cod*_*ict 8

是的,您可以使用返回值printf作为函数参数.
但请记住printf,成功返回写入的字符数.
所以

foo(printf("bar%d",123)); 
Run Code Online (Sandbox Code Playgroud)

不传递6foo函数bar123.

如果要传递printf打印的字符串,可以使用sprintf函数.它类似于printf但不是写入控制台而是写入char数组.