What is conditional operator and it's syntax in C

Interview Questions
  • What is conditional operator and it's syntax in C.
  • What is the logical operator in C.
  • What is the bitwise operator in C.

What is conditional operator and it's syntax in C

Conditional Operator is a powerful Operator which can be used to implement if-then-else type of logic. This operator is also known as ternary operator and it takes three arguments in the following form.

Conditional_Expression ? Expression_One : Expression_Two;
Ternary Operator will execute Expression_One if Conditional_Expression is true, otherwise it execute Expression_Two.
Ternary Operator is similar to if-else decision block as it evaluates only one code block depending on the result of Conditional_Expression.
For Example
int X = 25;
int Y = (X > 20 ? 1 : 2);
As X > 20, So after above statement Y's value becomes 1.


What is assignment operators in C

Assignment Operators of C is used to assign a value to a variable. "=" is called simple arithmetic operator of C, it assigns values from right side operands(R value) to left side operand (L value). The general syntax of assignment operator is:

variable_name = expression;
For Example
value = 1234;
value = 4/2;


What is the bitwise operator in C

C is a middle level language, it support many operations which can be performed in assembly language like operations on bits. Bitwise operators performs bit-by-bit operations on operands. There are six bitwise operators supported by C programming language.

  • Bitwise OR Operator(|)
  • Bitwise AND Operator(&)
  • NOT Operator(One's Complement)(~)
  • Bitwise Exclusive OR Operator(^)
  • Right Shift Operator(>>)
  • Left Shift Operator(<<)
Bitwise Operators can only be applied on char and integer operands. We cannot use bitwise operators with float, double, long double, void and other user define complex data types.


Related Topics
What are the different types of operator in C.
What is assignment operators in C
What is the use of sizeof() function in C
What is the difference between = and == operators in C
What will happen if break statement is not used in switch case in C
Why is default statement used in switch case in C
What is global variable in C
What is local variable in C
What is enum data type in C
Pointer to a function in C.