Knowee
Questions
Features
Study Tools

What will be output when you will execute following c++ code?int main(){int a=5,b=10;if(++a||++b)printf(“%d  %d”,a,b);elseprintf(“Doraemon”);}1,24,95,96,10

Question

What will be output when you will execute following c++ code?

int main() {
    int a = 5, b = 10;
    if (++a || ++b)
        printf("%d  %d", a, b);
    else
        printf("Doraemon");
}

1, 24, 95, 96, 10

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given C++ code will be "6 10".

Here's the step by step explanation:

  1. In the main function, two integer variables 'a' and 'b' are declared and initialized with values 5 and 10 respectively.

  2. Then there is an if condition with a logical OR operator. The condition checks if either '++a' or '++b' is true.

  3. The '++a' operation is a pre-increment operation, which means the value of 'a' is incremented by 1 before the condition is checked. So, 'a' becomes 6.

  4. In a logical OR operation, if the first condition is true, the second condition is not checked. Since '++a' is true (as 6 is a non-zero and hence, true value in C++), '++b' is not executed.

  5. Therefore, the printf statement inside the if block is executed, which prints the values of 'a' and 'b'. So, "6 10" is printed.

  6. The else block is not executed because the if condition is true. So, "Doraemon" is not printed.

This problem has been solved

Similar Questions

What will be output when you will execute following c++ code?int main(){int a=5,b=10;if(++a||++b)printf(“%d  %d”,a,b);elseprintf(“Doraemon”);}1,24,95,96,10

find the output of given code.#include <stdio.h>int main(){int a,b=110,c=20;printf("%d",a=b-=c*=5);return 0;}

What will be the output of following program?main( ){int k, num = 30 ;k = ( num > 5 ? ( num <= 10 ? 100 : 200 ) : 500 ) ;printf ( "\n%d", num ) ;}

What will be the output of the following program? #include<stdio.h> int main() { int i=10; if (i > 10) else printf ( "Hello Cocaine!" ); return 0; }

what is the output of the given program?main(){#ifndef sanprintf("no");#endifprintf("yes");}

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.