Outputting nothing

closed account (jNU5fSEw)
Is it possible to output a variable with no value? Also, is there a code to know if a variable has a value? I need this concepts. Help. Urgent.
What do you mean by "no value"?
1
2
3
int a ; // i.e. unitialized
int b = 0 ; // i.e. zero
double c = 1.0/0.0 ; // i.e. NaN 


In these cases: Simply test it!

Otherwise you have to bee more specific ;-).

Also, is there a code to know if a variable has a value?

I can tell you this is not possible for any integral type since you cannot tell if a certain value was assigned or is still the initial value. You can however if you know your numbers are always positive you can treat variables containing negative numbers as "having no value".

In other cases you will have to use your own class and mark data if it has been set or is still the initial value.
closed account (jNU5fSEw)
I tested outputting a variable with no value. I got a delta character. However, I don't want to have this character.
Well I suggest you initialize the variable then. The computer randomly selects something to throw in uninitialized variables.
I'm curious, what compiler are you using? Attempting to output an uninitialized variable should throw a compile or runtime error.
Perhaps a compile-time warning at best, but definitely not an error.

OP is basically doing

char ch;
cout << ch;

and getting whatever character happened to be on the stack at the address of ch.
Topic archived. No new replies allowed.