C++ – calculating expression without using semicolon

cobfuscation

Given the expression by input like 68+32 we have to evaluate without using a semicolon in our program. If it will be something inside the if or for loop?
Reference : https://www.spoj.pl/problems/EXPR2/

Best Answer

You can use if and the comma operator, something like this:

if( expr1, expr2, expr3, ... ) {}

It would be equivalent to

expr1;
expr2;
expr3;
...

To use variables without any warnings you can define a function the recieves the data types you need that you call from your main, like so:

void myFunc(int a, double b) {
    if ( expr1, expr2 ) { }
}
int main() {
    if ( myFunc(0, 0), 0 ) { }
}

Note that you need to add , 0 in main, otherwise an error is raised because a void return is not ignored.