0

For a char variable would i also set it to 0 as i would set and int or a float or any other variable?

Such as

char test = 0 

would it be like that since

int test = 0 

would be like that?

1
  • What are you actually trying to accomplish? What are you going to do with it after you "clear" it? Store another value? Print it? Commented Oct 10, 2011 at 6:53

2 Answers 2

3

Which do you want? The character '0', or the ascii 0?

If you want to set it to the character '0', then you need:

char test = '0'; 

If you want the ascii value 0, then it's fine the way it is.

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

8 Comments

I just want it to be cleared with nothing. Basically as int would be 0 yeah.
Variables don't really need to be "cleared". If you're going to write to it on the first use, you don't need to initialize it to anything.
More strongly, char and int values cannot be cleared, they always contain a valid value.
So i can literally use char test; and thats it?
Correct. It doesn't need to be initialized.
|
0

You can always use type conversions in c++, so even if you write int test = 0 you can access its ascii by converting it into char, this goes without saying for chars

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.