C# Arithmetic and Relational Operators

AttractiveVampire avatar
AttractiveVampire
·
·
Download

Start Quiz

Study Flashcards

18 Questions

The $String$ class is the base class for all data types in C#.

False

In C#, a variable name can start with a digit.

False

In C#, the $int$ keyword is used to declare a variable of type $String$.

False

Operators in C# are used to perform operations on variables and data types.

True

In C#, compile-time initialization is a way to assign a value to a variable at runtime.

False

A variable in C# can be declared without assigning a value to it.

True

In C#, the logical operator AND has a higher precedence than the logical operator OR.

True

The arithmetic operator % is used for exponentiation in C#.

False

In C#, the relational operator == is used to assign a value to a variable.

False

The unary operator ! is used to perform a logical NOT operation in C#.

True

In C#, a single-line comment starts with a double apostrophe ''.

False

The if-else statement in C# is used to execute a block of code if the given condition is false.

False

In C#, a switch statement can be used to replace an if-else statement.

True

In a do/while loop, the condition is checked before the code block is executed.

False

A for loop is used when the exact number of iterations is unknown.

False

In an if-else statement, the code inside the else block is executed if the expression is evaluated to true.

False

The code inside an if block is executed as soon as the test expression is false.

False

A while loop and a do/while loop are interchangeable in C#.

False

Study Notes

C# Basics

  • In C#, string and String are equivalent, and they represent a sequence of Unicode characters.
  • System.String is the type name for string.

Object Class

  • The Object class is the base class for all data types in C#.
  • All types, predefined and user-defined, reference types and value types, inherit directly or indirectly from Object.
  • Type conversion is needed before assigning values to an Object.

Variables

  • A variable declaration consists of type variable_name = value;
  • The type defines the type of information to be stored in the variable.
  • The variable_name must be a valid identifier.
  • The value is the actual data to be stored in the variable.

Naming Variables

  • Variable names can contain letters ‘a-z’ or ’A-Z’, digits 0-9, and the character ‘_’.
  • Variable names cannot start with a digit.
  • Variable names cannot be C# keywords (e.g. int, float, null, String, etc.).

Initializing Variables

  • Initialization means assigning a value to a variable.
  • There are two ways to initialize variables: Run Time Initialization and Compile Time Initialization.

Operators

  • Operators are used to perform operations on variables and values.
  • There are various types of operators in C#, including Arithmetic, Relational, Logical, and Unary operators.

Arithmetic Operators

  • Arithmetic operators are used to perform arithmetic operations (e.g. addition, subtraction, multiplication, division, etc.).

Relational Operators

  • Relational operators are used in decision making and loops.
  • They are used to compare values and return a Boolean value.

Logical Operators

  • Logical operators are used to perform logical operations (e.g. AND, OR).
  • They operate on Boolean expressions and return a Boolean value.

Unary Operators

  • Unary operators operate on a single operand.

Comments

  • Single Line Comments start with a double slash //.
  • Multi Line Comments start with /* and end with */.

Decision Making

  • if statements execute a block of code if a condition is true.
  • if-else statements execute a block of code if a condition is true, otherwise execute another block of code.
  • if-else-if statements execute a block of code if a condition is true, otherwise check another condition.
  • switch statements are used to replace if-else statements.

Loops

  • while loops execute a block of code as long as a condition is true.
  • do/while loops execute a block of code once, then check the condition, and repeat if true.
  • for loops execute a block of code for a specified number of iterations.

This quiz covers arithmetic operators and relational operators in C#. It tests knowledge of operators supported by C# and their usage in decision making and loops.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

C Operator Mastery Quiz
10 questions

C Operator Mastery Quiz

TrustedReasoning avatar
TrustedReasoning
Operators in Programming Quiz
5 questions
Rational Number Problems
9 questions

Rational Number Problems

ReplaceableHarmonica avatar
ReplaceableHarmonica
Use Quizgecko on...
Browser
Browser