开发者

simple C/C++ question

开发者 https://www.devze.com 2023-02-16 21:42 出处:网络
I do that: char asa[2]; char c = \'2\'; 开发者_C百科asa[0] = c; asa[1] = \'\\0\'; printf(\"%s\", asa);

I do that:

char asa[2];
char c = '2';
开发者_C百科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...


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.


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'; line. The value should update immediately. If not its likely an issue with the debugger and not your code.

0

精彩评论

暂无评论...
验证码 换一张
取 消