什么是const X cx = {1}; [英] what is const X cx={1};

查看:103
本文介绍了什么是const X cx = {1};的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




是什么意思

其中X是

struct X

{

int i;

}

const X cx = {1};


帮助

sandspiderX

Hi,

What is meant by
where X is
struct X
{
int i;
}
const X cx={1};

Help
sandspiderX

推荐答案



" sandSpiderX" < M7 ********* @ gmail.com>在消息中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...

"sandSpiderX" <m7*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...



其中X是什么意思
struct X
{
int i;
}
const X cx = {1};

帮助
sandspiderX
Hi,

What is meant by
where X is
struct X
{
int i;
}
const X cx={1};

Help
sandspiderX




它正在用cx.i初始化cx分配给1.与X cx相同; cx.i = 1;


更多例子:


struct font

{

int size;

char * family;

int color_red;

int color_green;

int color_blue;

bool粗体;

bool斜体;

};


//你可以写

font myfont = {12," times new roman",255,10,10,true,false};


//而不是

font myfont2;

myfont2.size = 12;

myfont2.family =" times new roman" ;;

myfont2 .color_red = 255;

myfont2.color_green = 10;

myfont2.color_blue = 10;

myfont2.bold = true;

myfont2.italic = false;


问候,

ben



It''s initializing cx with cx.i assigned to 1. Same as X cx; cx.i = 1;

more example:

struct font
{
int size;
char* family;
int color_red;
int color_green;
int color_blue;
bool bold;
bool italic;
};

// you can write
font myfont = {12, "times new roman", 255, 10, 10, true, false};

// instead of
font myfont2;
myfont2.size = 12;
myfont2.family = "times new roman";
myfont2.color_red = 255;
myfont2.color_green = 10;
myfont2.color_blue = 10;
myfont2.bold = true;
myfont2.italic = false;

regards,
ben




" benben" <是****** @ hotmail.com>在留言中写道

news:42 ********************** @ news.optusnet.com.au ...

"benben" <be******@hotmail.com> wrote in message
news:42**********************@news.optusnet.com.au ...

sandSpiderX < M7 ********* @ gmail.com>在消息中写道
新闻:11 ********************** @ g14g2000cwa.googlegr oups.com ...

"sandSpiderX" <m7*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...



的含义是什么?
struct X
{
int i;
}
const X cx = {1};

帮助
sandspiderX
Hi,

What is meant by
where X is
struct X
{
int i;
}
const X cx={1};

Help
sandspiderX



它正在初始化cx,cx.i分配给1.与X cx相同; cx.i = 1;

更多例子:

struct font
{int / size>
char * family;
int color_red;
int color_green;
int color_blue;
bool bold;
bool italic;
};

//你可以写
字体myfont = {12," times new roman",255,10,10,true,false};

//而不是
字体myfont2;
myfont2.size = 12;
myfont2.family =" times new roman" ;;
myfont2.color_red = 255;
myfont2.color_green = 10;
myfont2.color_blue = 10;
myfont2.bold = true;
myfont2.italic = false;

问候,



It''s initializing cx with cx.i assigned to 1. Same as X cx; cx.i = 1;

more example:

struct font
{
int size;
char* family;
int color_red;
int color_green;
int color_blue;
bool bold;
bool italic;
};

// you can write
font myfont = {12, "times new roman", 255, 10, 10, true, false};

// instead of
font myfont2;
myfont2.size = 12;
myfont2.family = "times new roman";
myfont2.color_red = 255;
myfont2.color_green = 10;
myfont2.color_blue = 10;
myfont2.bold = true;
myfont2.italic = false;

regards,
ben




但是你还要添加''const''关键字,它告诉编译器

你不会改变X的值。


Allan



but you are also adding the ''const'' keyword which says to the compiler that
you are not going to change the value of X.

Allan


sandSpiderX写道:
sandSpiderX wrote:


是什么意思/>其中X是
struc t X
{
int i;
}
const X cx = {1};

帮助
sandspiderX
Hi,

What is meant by
where X is
struct X
{
int i;
}
const X cx={1};

Help
sandspiderX




这是一种初始化结构变量cx的方法,使得cx.i =

1.如果在X中声明了更多成员,那么你可以做到

{1,3 ....}


const关键字告诉cx变量一旦初始化将不会

有修改其成员的价值。



This is a way to initialise the structure variable cx such that cx.i =
1. If there were more members declared in X then you could have done
{1,3....}

The const keyword tells that the cx variable once intialised will not
have the value of its members modified.


这篇关于什么是const X cx = {1};的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆