-
Which of the following is the correct output for the program given below?
#include <stdio.h>
int main ( )
{
int a = 4, b = -1, c = 0, p, q, r, s;
p = a || b || c;
q = a && b && c;
r = a || b && c;
s = a && b || c;
printf ("%d %d %d %d\n", p, q, r, s);
return 0;
}
-
- 1 1 1 1
- 1 1 0 1
- 1 0 0 1
- 0 1 1 1
- 1 0 1 1
Correct Option: E
Step 1: int a=4, b=-1, c=0, p, q, r, s;
here variable a, b, c, p, q, r, s are declared as an integer type and the variable a, b, c are initialized to 4, -1, 0 respectively.
Step 2: p = a || b || c; becomes p = 4 || -1 || 0;. Hence it returns TRUE. So, p=1
Step 3: q = a && b && c; becomes q = 4 && -1 && 0; Hence it returns FALSE. So, q=0
Step 4: r = a || b && c; becomes r = 4 || -1 && 0; Hence it returns TRUE. So, r=1
Step 5: s = a && b || c; becomes s = 4 && -1 || 0; Hence it returns TRUE. So, s=1.
Step 6: printf("%d, %d, %d, %d\n", p, q, r, s); Hence the output is "1, 0, 1, 1".