c语言。C++问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 01:04:05
下列程序的执行结果是( )
using System;
class temp
{ enum team{ my,you=5,his,her=his+10};
public static void Main( )
{
Console.WriteLine(“{0},{1},{2},{3}”,(int)team.my , (int)team.you , (int)team.his , (int)team.her ) ;
}
}
A . 0,1,2,3 B. 0,4,0,10 C. 0,5,6,16 D. 1,4,5,15
也不知道这事不是C++的题,一点也不会,麻烦写详细点

C
其实就是枚举型的赋值问题

enum team
{
my, //enum的第一项如果没有显式的赋值,那么默认值为0
you=5,//you被赋值为5
his, //枚举型的中间项,如果显式的赋值,那么默认值为上一项加一,所以his为6
her=his+10 //her的值为his+10,所以为16
};

是C#的 答案C

enum team{ my,you=5,his,her=his+10};
枚举
不指定植则从0开始依次增加1;
前面有赋值,后未赋值, 后面的依次加1