okami
okami

Reputation: 2153

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...

Upvotes: 0

Views: 127

Answers (3)

Cody
Cody

Reputation: 3764

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.

Upvotes: 0

Marlon
Marlon

Reputation: 20314

The code is correct, yes. As for why your values aren't being updated it probably has to do with your IDE.

Upvotes: 2

Brian Roach
Brian Roach

Reputation: 76888

Yes, that is correct.

And my answer needs to be at least this long.

Upvotes: 2

Related Questions