FAQs on Operators in C++ - 3 Video Lecture - Crash Course for EmSAT Achieve
1. What are the different types of operators in C? |
|
Ans. There are several types of operators in C, including arithmetic operators (+, -, *, /, %), relational operators (>, <, >=, <=, ==, !=), logical operators (&&, ||, !), assignment operators (=, +=, -=, *=, /=), bitwise operators (&, |, ^, <<, >>), and conditional operator (?:).
2. How are arithmetic operators used in C? |
|
Ans. Arithmetic operators in C are used to perform basic mathematical operations. For example, the addition operator (+) is used to add two numbers, the subtraction operator (-) is used to subtract one number from another, the multiplication operator (*) is used to multiply two numbers, the division operator (/) is used to divide one number by another, and the modulus operator (%) is used to find the remainder after division.
3. What are the relational operators in C and how are they used? |
|
Ans. Relational operators in C are used to compare two values and determine the relationship between them. The greater than operator (>) checks if the value on the left is greater than the value on the right. The less than operator (<) checks if the value on the left is less than the value on the right. The greater than or equal to operator (>=) checks if the value on the left is greater than or equal to the value on the right. The less than or equal to operator (<=) checks if the value on the left is less than or equal to the value on the right. The equal to operator (==) checks if the two values are equal. The not equal to operator (!=) checks if the two values are not equal.
4. How are logical operators used in C? |
|
Ans. Logical operators in C are used to combine multiple conditions and evaluate the result. The logical AND operator (&&) returns true if both conditions on the left and right are true. The logical OR operator (||) returns true if at least one of the conditions on the left or right is true. The logical NOT operator (!) reverses the result of a condition, returning true if the condition is false and false if the condition is true.
5. What is the conditional operator in C and how is it used? |
|
Ans. The conditional operator (?:) in C is a ternary operator that allows you to perform a conditional expression. It takes three operands: a condition, a result if the condition is true, and a result if the condition is false. The operator evaluates the condition, and if it is true, it returns the result for the true case; otherwise, it returns the result for the false case. This operator is often used as a shorthand for if-else statements.