我真的可以用方括号初始化数组吗? [英] Can I really initialize an array with round brackets?
本文介绍了我真的可以用方括号初始化数组吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有时候,我在程序代码的一个地方打错了文字:
Occasionaly, I've made a typo in one place of code of my program:
int a = 10;
char* b = new char(a);
错误很明显:我写了()而不是[].奇怪的是...代码已正确编译,已在调试器中正常运行.但是,执行了这些行的功能后,调试器外部的已编译.exe崩溃了.
Error is obvious: I've written () instead of []. The strange thing is... code compiled ok, it ran in debugger ok. But compiled .exe outside of debugger crashed a moment after function with these lines was executed.
第二行代码真的合法吗?如果是的话,对编译器意味着什么?
Is second line of code really legitimate? And if it is, what does it mean to compiler?
推荐答案
它是单个字符,其数值为a
,在本例中为10
.知道,指针不仅指向数组.
It's a single char with the numerical value of a
, in this case 10
. Pointers don't only point to arrays, y'know.
这篇关于我真的可以用方括号初始化数组吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文