Day#88 C' Coding Challenge

Day#88 C' Coding Challenge

What is the output of the below code?

#include<stdio.h> #define FALSE 0 #define OUTPUT printf("Talent");printf(" Eve"); int main() { int var_1=1; if(var_1--) OUTPUT else printf("embeddeddesignblog"); return FALSE; }

-----------------------------------------------------------------

The above code has a simple if-else conditional check statements. When if statement is executed, it checks for var_1 and the condition passes as var_1 is 1. Post decrement is performed once the condition is checked. So, the execution enters if statement, where OUTPUT macro is seen.

The macro has two printf statements, printf("Talent");printf(" Eve");

After considering the macro, the if-else looks as below:

if(var_1--)

    printf("Talent");
    printf(" Eve");
else
    printf("embeddeddesignblog");

The if statement must have opening and closing braces if there is more than one statement. Here there are two statements and the program throws error as else statement cannot associate with if as there is printf between.

When the above code is executed,it throws compilation error:
[Error] 'else' without a previous 'if'

Post a Comment

0 Comments