简体   繁体   中英

C++ define function syntax with rand

I am working on a class assignment with starter code and included is this syntax that I've never seen before.

#define EVENT() (rand() % 2 > 0.5)

Can someone tell me what this does? Does it return something? I know the define is a macro that has a function called EVENT(), but what does the (rand() % 2 > 0.5) bit mean? If I use EVENT() in the code somewhere, do I treat it as a void function that just evaluates to that statement?

无论在源代码中使用EVENT()的哪个位置,预处理器都将EVENT()替换为rand()%2> 0.5,这将返回随机数1或0,如果rand()结果为奇数则返回1,如果结果为偶数则返回0 。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM