Whenever expressions
are connected together using the logical operators &&(AND) or || (OR),
only as many expressions as are needed to determine the overall logical value
will be evaluated. This is known as short-circuit behavior. For example,
if two expressions are connected with && and the first expression is
false, then it is guaranteed that the second expression will not be evaluated.
The same is true of expressions connected with || where the first expression is
true.
Write the output of the following C code segment.
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->
int i, j;
i = 2 && (j = 2); /* what is printed */
printf(“%d %d\n”, i, j);
(i = 0) && (j = 3);
printf(“%d %d\n”, i, j);
i = 0 || (j = 4);
printf(“%d %d\n”, i, j);
(i = 2) || (j = 5);
printf(“%d %d\n”, i, j);
형들... 이거 뭐 하라는거죠?
뭐 하라는건지는 모르겠고 설명하는거 보면 &&연산자의경우 앞의 조건문이 거짓이면 뒤의 조건문은 수행하지 않는다는거고(어차피 뭘해도 거짓이기때문에) 마찬가지로 ||연산자에서 앞의 조건문이 참이면 그냥 참으로 판단하기때문에 뒤의 조건문은 수행하지 않는다는 이야기 같음.
그래서 코딩 해보니까
1 2
0 2
1 4
2 4
이런식으로 나오는데 저거 이유를 쓰라는데 도통 모르겟어요... 조건문이 참 거짓을 판단하려는데 저기 i랑 j가 상수인데 .. 아 ㅠㅠ 이번에 처음 들어서 진짜 모르는게 너무 많네요...
숏서킷 내용이다 이미 맨위댓글이 같은내용을 써놨으니 생략하고 문제가 좀 정확하지않은듯?
아 순차적으로 바뀌는거네
맨위댓글처럼 숏서킷이기때문에 and 일때 앞이 거짓 즉 0이면 뒤에 배정문 생략됌 그래서03이 아니라 02가 나오는거임 그전줄에서 j가 2로 배정되었으니까
or은 니가 풀어보셈 숏셔킷이해하면 모를수가 없음