Week 2 Flashcards
(91 cards)
An operator is …
~ a symbol of the programming language which is able to operate on the values, such as e.g. + or =
What is the relationship between dividend and divisor?
5 / 2 = 2.5
5 is the dividend
2 is the divisor
What is going to happen if your function tried to divide by 0?
- it is strictly forbidden
- you will get a compilation error and won’t be able to run the program
- the error might not be shown to you, your program might just terminate abnormally
The ‘-‘ operator can be both, a … and a … operator
unary, binary
What is a unary operator?
A unary operator expects only one argument. For example, a ‘-‘ can denote a negative number. In this case, it is unary. In an arithmetic operation involving subtraction it might be binary.
10 - 8 = 2
10 is the …
8 is the …
minuend, subtrahend
To use a ‘+’ sign as a unary operator is possible, that is … You could use it to … But it is in most cases …
syntactically correct, preserve the sign, redundant
Multiplication … addition in mathematics. C preserves this hierarchy of …
precedes, priority
What determines the order of computations performed by operators with equal priority?
binding
If we have several operators with equal order of priority which order of computations does C use?
left-sided binding (from left to right)
How do you calculate the remainder of a division in C?
- use the modulus operator:
int i,j,k
i=13
j=5
k=i%j
-> the remainder of i / j is k, that is 13 / 5 R 3, k = 3
What does the plus plus operator in C do?
- it increments by 1
- it would e.g. replace x = x + 1 by x++
How does C decrement a variable by 1?
- you can decrement the traditional way: DaysLeft = DaysLeft - 1
- or use C’s own way: DaysLeft–
‘Variable++’ is called …
… post-increment operator.
’–Variable’ is called …
… pre-decrement operator.
’++Variable ‘ is called …
… pre-increment operator.
‘Variable–’ is called …
… post-decrement operator.
What do post-increment/decrement operators do as opposed to the opposite?
- return the original (unchanged) variable’s value and then increment/decrement the variable by 1
- variable is modified first and then it’s value is used
What do pre-increment/decrement operators do as opposed to the opposite?
- Increment/decrement the variable by 1 and return its value already increased/reduced
- variable’s current value is used and then modified
What is the value of i and j?
int i,j;
i=4;
j=++i
i=5
j=5
What is the value of i and j?
int i,j;
i=1;
j=i++;
i=2
j=1
What is the order of priority for arithmetic and C-specific operators?
highest - 1): ++ -- + - (unary) 2: * / % 3: + - (binary) 4: < <= > >= 5:== != lowest - 6): = += -= *= /= %=
What is the binding for prefix and postfix operators?
Prefix: right to left
Postfix: left to right
What is the C shortcut operator for the following expression?
i = i + 2 * j;
i += 2 * j;