×

# include <stdio.h>

int main(void) { 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("w=%d x=%d y=%d z=%d\n",w,x,y,z); return 0; }

0
accept rate: 0%

 0 Please use sites like ideone to keep a good format to the code. For now its quite a small code so its readable. Here, the thing is that in C++, 0 is false and every nonzero value is true. || is an operator that returns true if any of the operands is true and && is an operator that returns false if any one of the operands is false. So. w=i||j||k will set w's value to be 1(true) because both i and j is true(4 and 1 respectively). Similarly, x will become 0, y will become 1(&& is executed before ||) and z becomes 1. So, w, y and z are 1 and x is 0.Hope this helps :) answered 15 Sep '17, 19:26 2.4k●7●22 accept rate: 20% what if value of j is -1? (16 Sep '17, 12:14)
 0 If the value of j=-1, then also you will get same answer. The thing matters here is, value 0. Any non-zero value will be equivalent Boolean 1. So -1 also implies Boolean 1. answered 16 Sep '17, 12:51 5★vichitr 255●5 accept rate: 11%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×71

question asked: 15 Sep '17, 14:21

question was seen: 271 times

last updated: 16 Sep '17, 12:51