simple C/C++ question
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.
精彩评论