简体   繁体   English

简单的C / C ++问题

[英]simple C/C++ question

I do that: 我这样做:

char asa[2];
char c = '2';
asa[0] = c;
asa[1] = '\0';
printf("%s", asa);

is it right in terms of code validation? 在代码验证方面正确吗?

If I debug the asa values aren't updated untill the printf is called... 如果我调试asa值,直到printf被调用才更新...

Yes, that is correct. 对,那是正确的。

And my answer needs to be at least this long. 我的回答至少需要这么长。

The code is correct, yes. 该代码是正确的,是的。 As for why your values aren't being updated it probably has to do with your IDE. 至于为什么不更新您的值,这可能与您的IDE有关。

The code itself is correct. 代码本身是正确的。

As for the debugging thing are you sure that this is the case? 至于调试的事情,您确定是这种情况吗? Try checking the value of asa[0] when the debugger is on the asa[1] = '\\0'; 当调试器在asa [1] ='\\ 0'上时,请尝试检查asa [0]的值; line. 线。 The value should update immediately. 该值应立即更新。 If not its likely an issue with the debugger and not your code. 如果不是这样,则可能是调试器而不是您的代码出现了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM