C Operators & If Statement in C Language || C Notes

C Operators & If Statement in C Language || C Notes

 C Operators & If Statement in C Language || C Notes

In C programming language, operators are symbols that represent actions to be performed on operands. Operators can be used to perform a wide range of operations, from basic arithmetic calculations to more complex logical and bitwise operations. In this article, we will explore some of the most common operators in C and how they can be used in conjunction with if statements.

Arithmetic Operators:


Arithmetic operators are used to perform basic mathematical operations on numeric operands. The following are the most common arithmetic operators in C:

Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Modulo (%)
For example:


int a = 10, b = 5;
int sum = a + b;   // sum = 15
int diff = a - b;  // diff = 5
int prod = a * b;  // prod = 50
int quotient = a / b;  // quotient = 2
int remainder = a % b;  // remainder = 0


Relational Operators:


Relational operators are used to compare two values and return a boolean (true or false) result. The following are the most common relational operators in C:

Equal to (==)
Not equal to (!=)
Greater than (>)
Less than (<)
Greater than or equal to (>=)
Less than or equal to (<=)


For example:


int a = 10, b = 5;
if (a > b) {
  printf("a is greater than b");
}


Logical Operators:


Logical operators are used to combine boolean values and return a boolean result. The following are the most common logical operators in C:

Logical AND (&&)
Logical OR (||)
Logical NOT (!)


For example:



int a = 10, b = 5, c = 20;
if (a > b && a < c) {
  printf("a is between b and c");
}

Conditional Operator:


The conditional operator (?:) is a ternary operator that is used to evaluate a boolean expression and return one of two values depending on whether the expression is true or false. The syntax for the conditional operator is as follows:


condition ? value_if_true : value_if_false;
 

For example:


int a = 10, b = 5;
int max = (a > b) ? a : b;  // max = 10
If statement:

The if statement is a control statement that is used to execute a block of code if a specified condition is true. The syntax for the if statement is as follows:


if (condition) {
  // code to be executed if condition is true
}


For example:


int a = 10, b = 5;
if (a > b) {
  printf("a is greater than b");
}
The above code will print "a is greater than b" because the condition (a > b) is true.

Conclusion:

In conclusion, operators and if statements are essential components of C programming. Understanding how to use operators and if statements effectively is crucial for writing efficient and reliable code. With the knowledge gained from this article, you should be able to apply these concepts to your own C programming projects.

Watch Video 



All C  Topics : -

  1. C Language Intro

  2. Structure of C Language 

  3. Variable & data Types 

  4. Printf and Scanf Function

  5. Operator in c Language 

  6. If Statement in c Language 

  7. If else and Nasted if in C

  8. Switch Case In C 

  9. While loop in C Language 

  10. Exit Control Loop (Do While)

  11. For Loop in c 

  12. C Language Pratice Program 

  13. Goto Statement in c Programming 

  14. Array in c

  15. Pointer in  c Language 

  16. String in c Language 

Post a Comment (0)
Previous Post Next Post