小编Sum*_*a A的帖子

C++11 字符数组初始化和字符串文字

在 C++11 中,char指针不能直接初始化为字符串文字。
在早期版本的 C++ 中,我可以毫无问题地执行此操作。

如果允许使用以下代码:

char arr[] = "Hello";
char *p_str1 = arr;  //allowed
Run Code Online (Sandbox Code Playgroud)

那么为什么下面的代码不允许呢?

char *p_str3 = "Hello"; //Not allowed
Run Code Online (Sandbox Code Playgroud)

注意:我知道添加const可以修复。但我需要知道原因。

c++ arrays pointers string-literals c++11

2
推荐指数
1
解决办法
1063
查看次数

哪一种是比较Python中数字的更好方法?又为什么呢?

因此,如果我想比较Python中的数字,例如,检查数字是否落在2到100的范围内。
以下哪种方法最可取,为什么?

使用比较运算符?

if(n>=2 and n<=100):
    print("Okay")
Run Code Online (Sandbox Code Playgroud)

或使用range()函数?

if(n in range(2,101)):
    print("Okay")
Run Code Online (Sandbox Code Playgroud)

如果比较非常大,您的答案也会改变吗?

python python-3.x

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

标签 统计

arrays ×1

c++ ×1

c++11 ×1

pointers ×1

python ×1

python-3.x ×1

string-literals ×1