开发者

Assign single value to multiple variables

开发者 https://www.devze.com 2023-04-08 03:54 出处:网络
I want to开发者_开发问答 assign 0 to all declared values in a single statement. char r, g, b = 0;

I want to开发者_开发问答 assign 0 to all declared values in a single statement.

char r, g, b = 0;

The above only assigns 0 to b but not to the other variables


You can do it two ways:

char r = 0, g = 0, b = 0;

or

char r, g, b;
r = g = b = 0;


Tersest form is:

int r,g,b=g=r=0;
0

精彩评论

暂无评论...
验证码 换一张
取 消