EXPRESSION WEEK 2 Flashcards

1
Q

Question: What is the purpose of operators in programming languages?

A

Answer: Operators in programming languages are used to combine variables and constants into expressions for transforming existing data into new data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Question: What types of operands can be used with operators in programming languages?

A

Answer: The operands that can be used with operators in programming languages include variables, constants, or other expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Question: What types of operators are supported in the C language?

A

Question: What is the data type of a value yielded by a relational expression?

Answer: The value of a relational expression is of type int.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Question: What happens when operands of different types are used in an expression?

A

Answer: This chapter describes what happens when operands of different types are used in an expression, including how to change the type of an operand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Question: What are the hardware components that evaluate expressions?

A

Answer: The hardware components that evaluate expressions are the ALU and FPA inside the CPU.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Question: What expressions can the ALU process on integer types?

A

Answer: The ALU can process arithmetic, relational, and logical expressions on integer types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Question: What expressions can the FPA process on floating-point types?

A

Answer: The FPA can process arithmetic, relational, and logical expressions on floating-point types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Question: What are the types of operands used in arithmetic expressions?

A

Answer: Arithmetic expressions consist of integral operands for processing by the ALU and floating-point operands for processing by the FPA.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Question: How many binary and unary arithmetic operations does the C language support on integral operands?

A

Answer: The C language supports 5 binary and 2 unary arithmetic operations on integral (int and char) operands.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Question: What are the binary arithmetic operations on integers and what are their meanings?

A

Answer: The binary arithmetic operations on integers are addition, subtraction, multiplication, division and remaindering. Their meanings are as follows:

operand + operand: add the operands
operand - operand: subtract the right from the left operand
operand * operand: multiply the operands
operand / operand: divide the left by the right operand. If the division is not exact, the operation discards the remainder and the expression evaluates to the truncated integer result.
operand % operand: remainder of the division of left by right. The expression evaluates to the remainder alone.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Question: What are the unary arithmetic operations supported by the C language?

A

Answer: The unary arithmetic operations supported by the C language are identity and negation, which are represented by the expressions + operand and - operand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Question: What are the binary arithmetic operations on floating-point operands in C?

A

Answer: The binary arithmetic operations on floating-point operands in C are addition, subtraction, multiplication, and division, which are represented by the expressions operand + operand, operand - operand, operand * operand, and operand / operand.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Question: Does the division operator (/) for floating-point operands in C evaluate to a whole number or a floating-point result?

A

Answer: The division operator (/) for floating-point operands in C evaluates to a floating-point result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Question: What is the purpose of the plus operator in C arithmetic expressions involving unary operations?
.

A

Answer: The plus operator in C arithmetic expressions involving unary operations is present for language symmetry and leaves the value unchanged

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Question: What are relational expressions in C language, and how many relational operations does it support?

A

Answer: Relational expressions in the C language evaluate a condition and compare two values, yielding 1 if the condition is true and 0 if the condition is false. The C language supports 6 relational operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Question: What is the data type of a value yielded by a relational expression?

A

Answer: The value of a relational expression is of type int.

17
Q

Question: What are the forms of relational expressions listed in C language, and what do they mean?

A

Answer: Relational expressions in the C language take one of six forms: operand == operand (operands are equal), operand > operand (left is greater than the right), operand >= operand (left is greater than or equal to the right), operand < operand (left is less than the right), operand <= operand (left is less than or equal to the right), and operand != operand (left is not equal to the right).

18
Q

Question: What types of operands are allowed in relational expressions in C language?

.

A

Answer: The operands may be integral types or floating-point types

19
Q

Question: What are logical expressions in the C language, and how does it interpret the values true and false?

A

Answer: Logical expressions in the C language are used to evaluate a condition. The C language does not have reserved words for true or false. It interprets the value 0 as false and any other value as true.

20
Q

Question: What are the three logical operators supported by the C language, and what do they mean?

A

Answer: The C language supports three logical operators: operand && operand (both operands are true), operand || operand (one of the operands is true), and ! operand (the operand is not true).

21
Q

Question: What is the data type of a value yielded by a logical expression?

A

Answer: The value of a logical expression is of type int.

22
Q

What is deMorgan’s Law in C programming?

A

Answer: deMorgan’s Law is a rule that allows the conversion of compound conditions in logical expressions. It states that the opposite of a compound condition is the compound condition with all sub-conditions reversed, all &&’s changed to ||’s and all ||’s to &&’s.

23
Q

What is an example of applying deMorgan’s Law in C programming?

A

Answer: One example of applying deMorgan’s Law is in defining an adult in C as “!child && !senior”, which is logically equivalent to the expression “!(child || senior)”.

24
Q

What are shorthand assignments in C programming?

A

Answer: Shorthand assignments are operators that combine an arithmetic expression with an assignment expression in C programming. They store the result of the arithmetic expression in the left operand.

25
Q

What are the binary shorthand assignment operators for integral operands in C programming?

A

Answer: C programming has 5 binary shorthand assignment operators for integral (int and char) operands. These operators are +=, -=, *=, /=, and %=

26
Q

What is the meaning of the shorthand operator “operand += operand” in C programming?

A

Answer: The shorthand operator “operand += operand” in C programming is equivalent to the longhand expression “i = i + 4”. It adds 4 to the value of i and assigns the result to i.

27
Q

Question: What are unary operators in C language?

A

Answer: Unary operators are operators in C language that operate on a single operand. In C language, there are two types of unary operators: prefix and postfix. Prefix operators precede their operands, while postfix operators follow their operands. Examples of unary operators in C language include ++ and –.

28
Q

Question: What is the difference between prefix and postfix expressions in C language?
.

A

Answer: The main difference between prefix and postfix expressions in C language is in the value of the expression itself. The prefix operator changes the value of its operand and sets the expression’s value to be the changed value. The postfix operator, on the other hand, sets the expression’s value to the operand’s original value and then changes the operand’s value

29
Q

Question: How do prefix and postfix operators work on floating-point operands in C language?

A

Answer: Prefix and postfix operators operate on floating-point operands in the same way as on integral operands in C language.

30
Q

Question: What are the binary shorthand assignment operators for floating-point operands in C language?

A

Answer: C language has four binary shorthand assignment operators for floating-point operands, which are: +=, -=, *=, and /=.

31
Q

Question: How can compact use of shorthand operators lead to ambiguity in C language?

A

Answer: Compact use of shorthand operators can lead to ambiguity in C language across different platforms. For example, in the statement “int j = i++ + i;”, one compiler may increment the first i before the addition, while another compiler may increment i after the addition. To avoid ambiguity, we can re-write the code to make our intent explicit

32
Q

Question: What is casting in C language?

A

Answer: Casting is a feature in C language that allows us to convert the type of an operand. To convert the type of an operand, we precede the operand with the target type enclosed within parentheses. We call such an expression a cast.

33
Q

Question: What are mixed-type expressions and why do we need rules for converting operands of one type to another type?

A

Answer: Mixed-type expressions are expressions with operands of different types. CPUs handle expressions with operands of the same type differently. Therefore, we need rules for converting operands of one type to another type to ensure that expressions with operands of different types can be processed by CPUs

34
Q

Question: What is the ranking of types in C language?

A

Answer: The ranking of types in C language from higher to lower is: long double, double, float, long long, long, int, short, char.

35
Q

Question: What is promotion and truncation in assignment expressions?

A

Answer: Promotion is the process of converting a lower type operand to a higher type operand when the left operand in an assignment expression is of a higher type than the right operand. Truncation is the process of converting a higher type operand to a lower type operand when the left operand in an assignment expression is of a lower type than the right operand.

36
Q

Question: What happens when C compilers evaluate an arithmetic or relational expression with operands of different types?

A

Answer: C compilers promote the operand of lower type to an operand of the higher type before evaluating the expression.

37
Q

Question: What are the rules of precedence in evaluating compound expressions in C?

A

Answer: C compilers evaluate compound expressions according to rules of precedence. The order of precedence, from highest to lowest, and the direction of evaluation are listed in the table below:

Operator Evaluate From
++ – (postfix) left to right
++ – (prefix) + - & ! (all unary) right to left
(type) right to left

/ % left to right
left to right
< <= > >= left to right
== != left to right
&& left to right
|| left to right
= += -= *= /= %= right to left

38
Q

Question: How can we change the order of evaluation in compound expressions?

A

Answer: We can change the order of evaluation in compound expressions by introducing parentheses. C compilers evaluate the expressions within parentheses before applying the rules of precedence.