Relational and Logical Operators in C Language

DurableOnyx944 avatar
DurableOnyx944
·
·
Download

Start Quiz

Study Flashcards

30 Questions

What does a relational operator return if the relation is true in C language?

1

Which operator is used for 'greater than' in C language?

>

What will be the output of the following code:

int a = 10, b = 20;
if (a > b)
    printf("a is greater than b");
else if (a < b)
    printf("a is less than b");
else
    printf("a is equal to b");```

a is less than b

Which relational operator is used to check if two values are not equal in C language?

<>

What will be the value of 'b' after the following code execution:

int a = 5, b;
b = (a == 5) ? 3 : 2;```

3

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

Evaluate relational operators first

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

Left to right

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

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

What is the syntax for the increment operator in C?

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

What does a relational operator return if the relation is false in C language?

0

What is the output of the C program with the arithmetic expression: x = 9 - 12 / (3 + 3) * (2 - 1)?

5

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?

90

What is the syntax for the conditional operator in C?

condition ? expression1 : expression2

Which operator is used for 'greater than or equal to' in C language?

>=

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

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.

Get started for free

More Quizzes Like This

SQL Basics Quiz
6 questions

SQL Basics Quiz

PowerfulPond avatar
PowerfulPond
Introduction to SQL Language
30 questions

Introduction to SQL Language

AffectionateUnderstanding45 avatar
AffectionateUnderstanding45
Use Quizgecko on...
Browser
Browser