C Programming - Expressions - Discussion
Discussion Forum : Expressions - Find Output of Program (Q.No. 6)
6.
What will be the output of the program?
#include<stdio.h>
int main()
{
int i=4, j=-1, k=0, w, x, y, z;
w = i || j || k;
x = i && j && k;
y = i || j &&k;
z = i && j || k;
printf("%d, %d, %d, %d\n", w, x, y, z);
return 0;
}
Answer: Option
Explanation:
Step 1: int i=4, j=-1, k=0, w, x, y, z; here variable i, j, k, w, x, y, z are declared as an integer type and the variable i, j, k are initialized to 4, -1, 0 respectively.
Step 2: w = i || j || k; becomes w = 4 || -1 || 0;. Hence it returns TRUE. So, w=1
Step 3: x = i && j && k; becomes x = 4 && -1 && 0; Hence it returns FALSE. So, x=0
Step 4: y = i || j &&k; becomes y = 4 || -1 && 0; Hence it returns TRUE. So, y=1
Step 5: z = i && j || k; becomes z = 4 && -1 || 0; Hence it returns TRUE. So, z=1.
Step 6: printf("%d, %d, %d, %d\n", w, x, y, z); Hence the output is "1, 0, 1, 1".
Discussion:
51 comments Page 5 of 6.
Megha salunkhe said:
1 decade ago
Please tell how step 4 got the result 1? How it is implemented?
Smruti ganvir said:
9 years ago
Make me understand how is 4 && -1 && 0 = 0?
Akash said:
1 decade ago
Make me understand how's 4 && -1 && 0 = 0.
Pallavi said:
1 decade ago
Can anyone explain step3 and step5 please ?
Prichita said:
8 years ago
How did we get x=0?
Why is it false?
Why is it false?
Rohit said:
1 decade ago
Is there any priority in solving?
Mahi said:
8 years ago
How is possible the value of w=1?
Nihsa said:
1 decade ago
Please explain detail expansion.
Sahithi said:
2 decades ago
Please give clear explanation.
Narendra said:
1 decade ago
Please give complete answer.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers