0

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

4
  • Welcome to Stack Overflow! What do you mean by "is it right?" What are you trying to do? It's hard to know what's "right" without also knowing what's "wrong." Commented Mar 16, 2011 at 1:44
  • Welcome okami. Your code is correct. Are you using a visual debugger to inspect the values of asa? Commented Mar 16, 2011 at 1:45
  • 3
    did you compile with optimizations? Commented Mar 16, 2011 at 1:45
  • On all debuggers I know, the (->) pointer in the source code pointing at the current line shows you what will be executed next. So if it points at (->) printf("%s", asa); that means the printf function will be called next. Commented Mar 16, 2011 at 1:52

3 Answers 3

2

Yes, that is correct.

And my answer needs to be at least this long.

Sign up to request clarification or add additional context in comments.

1 Comment

I prefer using ***** FILLER ****** ;-)
2

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.