Podcast
Questions and Answers
What is the result of the expression 10 % 3
?
What is the result of the expression 10 % 3
?
- 10
- 1 (correct)
- 3
- 0
Which of the following operators checks if two operands are not equal?
Which of the following operators checks if two operands are not equal?
- != (correct)
- ==
- <
- >
What does the operator >
do?
What does the operator >
do?
- Checks if the left operand is equal to the right operand
- Checks if the left operand is less than the right operand
- Checks if the left operand is greater than the right operand (correct)
- Checks if the left operand is less than or equal to the right operand
Which operator would you use to divide two integers in C and get an integer result?
Which operator would you use to divide two integers in C and get an integer result?
What will the expression 5 - 3 + 2
evaluate to?
What will the expression 5 - 3 + 2
evaluate to?
Flashcards are hidden until you start studying
Study Notes
Operators in C
1. Arithmetic Operators
- Addition (
+
): Adds two operands. - Subtraction (
-
): Subtracts the right operand from the left. - Multiplication (
*
): Multiplies two operands. - Division (
/
): Divides the left operand by the right (integer division if both are integers). - Modulus (
%
): Returns the remainder of the division of two integers.
2. Relational Operators
- Equal to (
==
): Checks if two operands are equal. - Not equal to (
!=
): Checks if two operands are not equal. - Greater than (
>
): Checks if the left operand is greater than the right. - Less than (
<
): Checks if the left operand is less than the right. - Greater than or equal to (
>=
): Checks if the left operand is greater than or equal to the right. - Less than or equal to (
<=
): Checks if the left operand is less than or equal to the right.
3. Logical Operators
- Logical AND (
&&
): Returns true if both operands are true. - Logical OR (
||
): Returns true if at least one operand is true. - Logical NOT (
!
): Inverts the truth value of the operand.
4. Bitwise Operators
- Bitwise AND (
&
): Compares each bit of two operands and returns 1 if both bits are 1. - Bitwise OR (
|
): Compares each bit and returns 1 if at least one bit is 1. - Bitwise XOR (
^
): Compares each bit and returns 1 if the bits are different. - Bitwise NOT (
~
): Flips all the bits in the operand. - Left Shift (
<<
): Shifts bits to the left, filling with zeros. - Right Shift (
>>
): Shifts bits to the right.
5. Assignment Operators
- Assignment (
=
): Assigns the value of the right operand to the left operand. - Add and assign (
+=
): Adds right operand to left operand and assigns the result. - Subtract and assign (
-=
): Subtracts right operand from left operand and assigns the result. - Multiply and assign (
*=
): Multiplies left operand by right operand and assigns the result. - Divide and assign (
/=
): Divides left operand by right operand and assigns the result. - Modulus and assign (
%=
): Applies modulus operator and assigns the result.
6. Increment and Decrement Operators
- Increment (
++
): Increases the value of the operand by 1. Can be prefix (++a) or postfix (a++). - Decrement (
--
): Decreases the value of the operand by 1. Can be prefix (--a) or postfix (a--).
7. Conditional (Ternary) Operator
- Ternary (
? :
): A shorthand for if-else. Syntax:condition ? expression_if_true : expression_if_false
.
8. Comma Operator
- Comma (
,
): Evaluates two expressions and returns the value of the second expression.
9. Sizeof Operator
- Sizeof: Returns the size (in bytes) of a data type or variable.
10. Pointer Operators
- Address-of (
&
): Returns the memory address of a variable. - Dereference (
*
): Accesses the value at the address specified by a pointer.
Each operator serves a specific role in C programming, enabling a wide variety of operations and manipulations to be performed on data. Understanding these operators is crucial for effective programming in C.
Arithmetic Operators
- Addition (
+
), Subtraction (-
), Multiplication (*
) perform standard mathematical operations. - Division (
/
) performs integer division if both operands are integers, meaning it only returns the whole number part of the result. - Modulus (
%
) returns the remainder after integer division.
Relational Operators
- Equal to (
==
) and Not equal to (!=
) compare if two operands are the same or different. - Greater than (
>
), Less than (<
), Greater than or equal to (>=
), and Less than or equal to (<=
) compare the values of two operands.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.