Akış
Ara
Ne Okusam?
Giriş Yap
Kaydol

Stephen G. Kochan

Stephen G. KochanProgramming in C yazarı
Yazar
0.0/10
0 Kişi
0
Okunma
0
Beğeni
93
Görüntülenme

Hakkında

Okurlar

1 okur okuyacak.
1 okur yarım bıraktı.
Reklam

Sözler ve Alıntılar

Tümünü Gör
Trying to predict the ways that a program can fail or produce unwanted results and then taking preventive measures to account for such situations is a necessary part of producing good, reliable programs. Running a sufficient number of test cases against a program often points the finger to portions of the program that do not account for certain cases. But it goes further than that. It must become a matter of self-discipline while coding a program to always say “What would happen if ...” and to insert the necessary program statements to handle the situation properly.
== ve =
Remember that the double equal sign == is the equality test and the single equal sign is the assignment operator. It can lead to lots of headaches if you forget this and inadvertently use the assignment operator inside the if statement.
Reklam
printf içinde şartlı operatör
It is not necessary that the conditional operator be used on the right-hand side of an assignment—it can be used in any situation in which an expression could be used. This means that you could display the sign of the variable number, without first assigning it to a variable, using a printf statement as shown: printf ("Sign = %i\n", ( number < 0 ) ? –1 : ( number == 0 ) ? 0 : 1);
şartlı operatör, conditional operator
The general format of the conditional operator is condition ? expression1 : expression2 where condition is an expression, usually a relational expression, that is evaluated first whenever the conditional operator is encountered. If the result of the evaluation of condition is TRUE (that is, nonzero), then expression1 is evaluated and the result of the evaluation becomes the result of the operation. If condition evaluates FALSE (that is, zero), then expression2 is evaluated and its result becomes the result of the operation. The conditional operator is most often used to assign one of two values to a variable depending upon some condition. For example, suppose you have an integer variable x and another integer variable s. If you want to assign –1 to s if x were less than zero, and the value of x^2 to s otherwise, the following statement could be written: s = ( x < 0 ) ? -1 : x * x;
değilleme operatörü, negation operator. ( ! )
To easily test if the value of a flag is FALSE, you can use the logical negation operator, !. In the expression if ( ! isPrime ) the logical negation operator is used to test if the value of isPrime is FALSE (read this statement as “if not isPrime”). In general, an expression such as ! expression negates the logical value of expression. So if expression is zero, the logical negation operator produces a 1. And if the result of the evaluation of expression is nonzero, the negation operator yields a 0. The logical negation operator can be used to easily “flip” the value of a flag, such as in the expression myMove = ! myMove; As you might expect, this operator has the same precedence as the unary minus operator, which means that it has higher precedence than all binary arithmetic operators and all relational operators. So to test if the value of a variable x is not less than the value of a variable y, such as in ! ( x < y ) the parentheses are required to ensure proper evaluation of the expression. Of course, you could have equivalently expressed the previous expression as x >= y
Henüz kayıt yok

Yorumlar ve İncelemeler

Tümünü Gör
Reklam
Henüz kayıt yok