नोट
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप साइन इन करने या निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
इस पृष्ठ तक पहुंच के लिए प्राधिकरण की आवश्यकता होती है। आप निर्देशिकाएँ बदलने का प्रयास कर सकते हैं।
assignment used as a condition
Remarks
The test value in a conditional expression is the result of an assignment.
An assignment has a value (the value on the left side of the assignment) that can be used legally in another expression, including a test expression.
Example
The following example generates C4706:
// compile with: /W4
int main()
{
int a = 0, b = 0;
if (a = b) // C4706
{
}
}
Suppress the warning with ((expression)). For example:
// compile with: /W4
int main()
{
int a = 0, b = 0;
if ((a = b)) // No warning
{
}
}
If your intention is to test a relation, not to make an assignment, use the == operator. For example, the following tests whether a and b are equal:
// compile with: /W4
int main()
{
int a = 0, b = 0;
if (a == b)
{
}
}
If you intend to make your test value the result of an assignment, test to ensure that the assignment is non-zero or non-null. For example, the following code doesn't generate this warning:
// compile with: /W4
int main()
{
int a = 0, b = 0;
if ((a = b) != 0)
{
}
}