# Relational and Logical Operators in C Language

DurableOnyx944
·

Start Quiz

Study Flashcards

## 30 Questions

1

>

a is less than b

<>

3

### What is the first step in evaluating expressions within parenthesis in C?

Evaluate relational operators first

Left to right

7

### What happens when nested parentheses are present in an arithmetic expression?

The inner parentheses are evaluated first and then the outer ones

### What is the output of the C program: d = a + c / b; printf('The value of d = %d ', d); where a = 2, b = 6, and c = 12?

The value of d = 4

var_name++;

### What does the increment operator (++var_name;) do?

Increase the value of var_name by one

### What is the output of the C program with the arithmetic expression: e = (a + b) * c / d; where a = 20, b = 10, c = 15, and d = 5?

Value of (a + b) * c / d is : 90

### What is the order of evaluation for arithmetic expressions with parentheses?

( ) first, then high priority, low priority

0

5

90

### What is the syntax for the conditional operator in C?

condition ? expression1 : expression2

>=

3

### What is the order of evaluation for arithmetic expressions with parentheses?

The expression inside the innermost set of parentheses is evaluated first and then the outer parentheses are evaluated.

### What happens when nested parentheses are present in an arithmetic expression?

The expression inside the innermost set of parentheses is evaluated first and then the outer parentheses are evaluated.

### How is the arithmetic expression x = 9 – 12 / (3 + 3) * (2 – 1) evaluated?

The expression is evaluated as: x = 7

### What is the output of the C program: d = a + c / b; printf('The value of d = %d ', d); where a = 2, b = 6, and c = 12?

The output is: The value of d = 4

### What is the syntax for the increment operator in C?

Increment operator: ++var_name; (or) var_name++;

### What is the syntax for the decrement operator in C?

Decrement operator: --var_name; (or) var_name--;

### What will be the value of 'e' after the following code execution: e = ((a + b) * c) / d; where a = 20, b = 10, c = 15, and d = 5?

The value of 'e' will be: 90

### What will be the value of 'b' after the following code execution: b = (a == 5) ? 3 : 2; where a = 5?

The value of 'b' will be: 3

### What is the first step in evaluating expressions within parenthesis in C?

The expression inside the parenthesis are evaluated first from left to right.

### What is the order of evaluation for arithmetic expressions without parentheses?

In arithmetic expressions without parentheses, the high priority operators are applied as they are encountered in the first pass, and low priority operations are applied as they are encountered in the second pass.

## Study Notes

### Relational Operators

• A relational operator returns 1 (true) if the relation is true and 0 (false) if the relation is false in C language.
• The 'greater than' operator in C language is >.

### Conditional Operator

• The conditional operator is used to check if two values are not equal in C language, denoted by !=.
• The syntax for the conditional operator in C is expression1 ? expression2 : expression3.

### Arithmetic Expressions

• When evaluating expressions within parentheses in C, the first step is to evaluate the expressions inside the parentheses.
• The order of evaluation for arithmetic expressions without parentheses is from left to right.
• When nested parentheses are present in an arithmetic expression, the innermost parentheses are evaluated first.
• The arithmetic expression x = 9 – 12 / (3 + 3) * (2 – 1) is evaluated as follows:
• Evaluate the expression inside the parentheses first: 3 + 3 = 6 and 2 - 1 = 1.
• Then, 12 / 6 = 2 and 9 - 12 / 6 * 1 = 9 - 2 * 1 = 7.

### Increment and Decrement Operators

• The syntax for the increment operator in C is ++var_name;.
• The increment operator ++var_name; increments the value of var_name by 1.
• The syntax for the decrement operator in C is --var_name;.

### Example Programs

• The output of the C program d = a + c / b; printf('The value of d = %d ', d); where a = 2, b = 6, and c = 12 is d = 2 + 12 / 6 = 4.
• The output of the C program with the arithmetic expression e = (a + b) * c / d; where a = 20, b = 10, c = 15, and d = 5 is e = (20 + 10) * 15 / 5 = 450 / 5 = 90.
• The output of the C program with the arithmetic expression x = 9 - 12 / (3 + 3) * (2 - 1) is x = 9 - 12 / 6 * 1 = 7.
• The value of b after the code execution b = ((a == 5) ? 3 : 2); where a = 5 is b = 3.

Test your knowledge of relational and logical operators in C language with this quiz. Learn about comparing values, using relational operators to check relationships between values, and the use of logical operators to make decisions based on multiple conditions.

## Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

## More Quizzes Like This

Use Quizgecko on...
Browser
Information:
Success:
Error: