小编cod*_*aif的帖子

启动枚举作为价值

我想将枚举变量声明为值.我怎样才能做到这一点?

例如:

public enum CardSuit {
   SPADE(0), HEART(1), DIAMOND(2), CLUB(3);
}
Run Code Online (Sandbox Code Playgroud)

我可以这样声明:

CardSuit s = CardSuit.SPADE;
Run Code Online (Sandbox Code Playgroud)

我也想这样声明:

CardSuit s = 1;
Run Code Online (Sandbox Code Playgroud)

这样做的方法是什么?这甚至可能吗?

java enums

3
推荐指数
1
解决办法
781
查看次数

Why does strlen in a if statement behave oddly?

#include <stdio.h>
#include <string.h>

int main()
{
    const char str[11]= "Hello World";
    if(-1 > strlen(str)){
        printf(str);
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

This if condition should always return false. But here it's not. But if I put strlen(str) value to another variable and compare with that, then it works as expected. What I am missing here? Is it compiler dependent or something?

c c++ unsigned strlen implicit-conversion

0
推荐指数
1
解决办法
343
查看次数

标签 统计

c ×1

c++ ×1

enums ×1

implicit-conversion ×1

java ×1

strlen ×1

unsigned ×1