You can easily define a variable inside an if . For example, this should compile:
if (int ch = getchar()) ;
The problem is that the type (e.g. int ) should follow immediately after opening the bracket. The extra bracket that you have is causing the compilation to fail. So, if you really want to do this, you need to think a little and use something like this:
if (char ch = 0 || ((ch = getchar()) == 0x1))
This allows you to get the creation and initialization of ch done, after this part of the expression is completed, put in parentheses around ch=getchar() to redefine the priority of destination and comparison.
Please note that && and || perform a short circuit assessment, so you need to be careful with your initialization. You can use either:
if (char ch = 0 || ...
... or:
if (char ch = 1 && ...
... but if you try to use if (ch = 1 || ... or if (ch = 0 && ... , the short circuit assessment will contain the correct operand (the part you really care about).
Now a word of caution: although I am sure that this code meets the standard requirements, and most (all?) Compilers will accept it, this will probably cause most programmers reading the code a serious scratch on their heads, figuring out what you have done and why. I would very much not dare (at best) to use this "technique" in real code.
Edit: It was pointed out that the result of this may be even more misleading than originally expected, so I will try to clarify the situation. It happens that the value is read from the input. This value is assigned to ch and is compared with 0x1 . So far, so good. After that, the comparison result (converted to an integer, therefore either 0 or 1 ) will be assigned to ch . I believe that it has a sufficient sequence of points, that the result is determined by behavior. But this is probably not what you, or anyone, want - thus, advice that you probably don't want to use, and a mention that it would probably leave most programmers scratching their heads, wondering the question is what were you trying to do. In the most specific case of comparison with 0x1, the value of ch inside the if will be 1 , but this is more or less a coincidence. If you were comparing with 0x2, the value of ch inside the if would still be 1 , not 2 .