Redefinition of Booleans and Varibles

Is there a way to redefine a variable or boolean?

Just a super quick example:

float one = 1.5f;
bool two = true;

    one = 2.0f;
    two = false;
    one = 0f;

is this python or c++

C++. Do you need it in python?


one = false
    one = true
   one = false
1 Like

What do you mean by ‘redefining’? Like changing the type (e.g. from int to float) midway through execution? Or just assigning a new value to a variable?

(The following assumes you have a globally defined variable.) For C/C++, technically you can use the same name in new scope (like a new function, a brace-enclosed switch/case, while loop, etc), but it’s a generally considered a bad idea. You leave a lot to the compiler/optimizer to do the right thing, and I can tell you from experience that you’re asking for trouble completely trusting a compiler to do the right thing.

Best behavior is to keep variables as unique as you can. Some exceptions for this will be things like loop counters like i, j, k, etc, which still have to be managed in scope carefully. Variables defined in functions are generally fine, but if you’re not naming things with some level of uniqueness, debugging will be a nightmare.


no ty, c++ is wut i am using

1 Like

sorry im just dumb. :frowning: