Week 2 Flashcards

(91 cards)

1
Q

An operator is …

A

~ a symbol of the programming language which is able to operate on the values, such as e.g. + or =

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

What is the relationship between dividend and divisor?

A

5 / 2 = 2.5
5 is the dividend
2 is the divisor

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

What is going to happen if your function tried to divide by 0?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The ‘-‘ operator can be both, a … and a … operator

A

unary, binary

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

What is a unary operator?

A

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.

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

10 - 8 = 2
10 is the …
8 is the …

A

minuend, subtrahend

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

To use a ‘+’ sign as a unary operator is possible, that is … You could use it to … But it is in most cases …

A

syntactically correct, preserve the sign, redundant

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

Multiplication … addition in mathematics. C preserves this hierarchy of …

A

precedes, priority

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

What determines the order of computations performed by operators with equal priority?

A

binding

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

If we have several operators with equal order of priority which order of computations does C use?

A

left-sided binding (from left to right)

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

How do you calculate the remainder of a division in C?

A
  • 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

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

What does the plus plus operator in C do?

A
  • it increments by 1

- it would e.g. replace x = x + 1 by x++

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

How does C decrement a variable by 1?

A
  • you can decrement the traditional way: DaysLeft = DaysLeft - 1
  • or use C’s own way: DaysLeft–
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

‘Variable++’ is called …

A

… post-increment operator.

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

’–Variable’ is called …

A

… pre-decrement operator.

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

’++Variable ‘ is called …

A

… pre-increment operator.

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

‘Variable–’ is called …

A

… post-decrement operator.

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

What do post-increment/decrement operators do as opposed to the opposite?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What do pre-increment/decrement operators do as opposed to the opposite?

A
  • Increment/decrement the variable by 1 and return its value already increased/reduced
  • variable’s current value is used and then modified
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the value of i and j?

int i,j;

i=4;
j=++i

A

i=5

j=5

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

What is the value of i and j?

int i,j;

i=1;
j=i++;

A

i=2

j=1

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

What is the order of priority for arithmetic and C-specific operators?

A
highest - 1): ++ -- + - (unary)
2: * / %
3: + - (binary)
4: < <= > >=
5:== !=
lowest - 6): = += -= *= /= %=
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the binding for prefix and postfix operators?

A

Prefix: right to left
Postfix: left to right

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

What is the C shortcut operator for the following expression?

i = i + 2 * j;

A

i += 2 * j;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the C shortcut operator for the following expression? Var = Var / 2;
Var /= 2;
26
What is the C shortcut operator for the following expression? Rem = Rem % 10;
Rem %= 10;
27
What is the C shortcut operator for the following expression? j = j - (i + Var + Rem);
j -= (i + Var + Rem)
28
What are floating numbers?
~ store numbers that have a non-empty decimal fraction
29
When can you omit zero?
- when it's the only digit in front or after the decimal point - the decimal point must be there to denote a floating-point number! (4. float vs 4 int)
30
Very large or very small numbers can be displayed in ...
... scientific notation.
31
Express 240000000 in scientific notation.
2.4E8
32
Write -0.000000523 in scientific notation.
-5.23E-7
33
With what word are floating-point numbers declared?
float
34
What happens when we’re forced to convert integer values into float values?
- can cause a lack of accuracy - the transformation affects the internal (machine) representation of those values, as computers use different methods for storing floats and ints in their memory
35
What happens when we’re forced to convert float values into integer values?
- will result in a loss of accuracy | - might not be feasible as integer variables have a limited capacity
36
What happens when a number conversion from float to int reaches maximum capacity?
- variable will be unable to store such a large value and there will be a loss of accuracy - but result of assignment unclear either max. permissible value or random value or an error will occur = implementation dependent issue (one side of portability)
37
A word is essentially a ...
... string of characters.
38
In C all strings are treated as ...
... arrays.
39
To store and manipulate characters, the “C” language provides a special type of data. What is this?
char
40
How do you assign string values to a variable called Character?
1) put the character/s in apostrophes: Character = 'A'; 2) use the ASCII code for A: Character = 65;
41
Why should you not use ASCII codes for char?
- it's illegible for someone who doesn't know ASCII | - computers that don't use ASCII can't work with it
42
What is ASCII?
= American Standard Code for Information Interchange ~ it's a universally accepted standard for character encoding - provides space for 256 different characters
43
The difference between the ASCII code for an uppercase letter and the same letter but in lower case is ..., which is the code for ...
32, whitespace
44
What types of characters does the ASCII code describe?
- letters - numbers - punctuation marks - symbols - whitespaces - control characters that control input/output devices
45
What kind of character coding framework do many IBM mainframes use?
EBCDIC (Extended Binary Coded Decimal Interchange Code)
46
What is a literal?
~ a symbol which uniquely identifies its value / a literal means itself
47
Is "CountBirds" a literal?
No, it is a variable and by looking at it you can't guess it's value.
48
Is "B" a literal?
Yes, because when you look at it you realise it's value straight away.
49
Is "i + 235" a literal?
It is a combination of a variable and a literal, called an expression.
50
What is the backslash \ used for in C?
- it is an escape character: you can escape from the normal meaning that follows the slash - e.g. Character = "\" allows you to escape from the normal meaning of the apostrophe to code the apostrophe itsself
51
How do you put the symbol backslash into a char variable?
Character = "\\" essentially you are escaping from the usual meaning of a backslash as an escape character
52
There are other escape characters. \n denotes a ... and is sometimes called an ..., as printers react to this character by pulling out the ...
- transition to a new line, LF (Line Feed)
53
What is \r and what does it do?
- denotes the return to the beginning of the line | - sometimes called a CR (Carriage Return)
54
What is \a and what does it do?
- officially called BEL (for bell) - it is an alarm tone - turns on a teletypes ringer
55
What does the escape character \0 do?
- called nul | - is a character that does not represent any character
56
What are octal digits?
~ digits from the range of 0 to 7 used in ASCII
57
A different way to escape is using an octal ...The sequence \ooo means you can specify any character in the ... character set as a three-digit octal character code. Octal escape sequences can never be longer than ... and are ... by the first character that is not an octal digit. You must use at least ... digit.
escape sequence, ASCII, 3 digits, terminated, 1
58
The sequence ... allows you to specify any ASCII character as a hexadecimal character code. You must use at least ... digit for a hexadecimal escape sequence, but you can omit the second and third digits. Unlike octal escape constants, the number of hexadecimal digits in an escape sequence is ... A hexadecimal escape sequence terminates at the first character that is not a ... Because hexadecimal digits include the letters a through f, care must be exercised to make sure the escape sequence terminates at the ...
\xhhh, 1, unlimited, hexadecimal digit, intended digit
59
What is the relationship between the char and int type? (4)
- char type is treated as a special kind of int type - you can assign a char value to an int variable, and vice versa - but expect a loss of value from int to a char variable if the value exceeds 255 (the top-most character code in ASCII) - value of the char type can be subject to the same operators as the data of type int
60
How can we check if 2 values are equal?
- with the (equal equal) operator == | - e.g. 2==2 true, 3==1 false
61
How can we ask if a value is unequal to another value?
DaysRemaining != 0
62
How would we code, are there more black sheep than white sheep?
- same as in mathematics: | BlackSheep > WhiteSheep
63
How do you use the greater than or equal operator in C?
4 >= 3
64
How do you memorise/store the answer from a greater or equal question?
int Answer, Value1, Value2 Answer = Value1 >= Value2 If Value2 is 5 and Value1 is 7, the statement is true. So, Answer will be 1. If Value2 is 3 and Value1 is 2, the statement is false. So, Answer will be 0.
65
How can we give a computer an instruction to take a specific action if a condition is met and abstain from taking action if that condition is not met? (4)
- through a conditional instruction / conditional statement if(expression that is either true or false) instruction; - if the expression is true (non-zero) the instruction will be executed - if the expression is false (0) the instruction is omitted
66
Code the following intention. "If the temperature is below 0 degrees, we go ice skating and then we will have some mulled wine at the stalls."
if(Temperature<0) GoSkating(); DrinkMulledWine();
67
How do you include more than one instruction in a conditional statement?
- with a compoud statement or block if($){(instruction1); (instruction2);}
68
How can you make sure your code doesn't run over the margins of the editor?
- have to apply styles | - most common is the K & R style (Kernighan and Ritchie style)
69
What is input?
~ sending data in the direction from human (user) to the computer program
70
The stream of data transferred in the opposite direction, i.e. from the computer to the human, is called ...
output
71
What is the impairment of the puts function?
- you can't use it if you want to print an integer value or a single character
72
What does the printf function do?
This function can easily output several values of different types and mix them with the text.
73
What requirements does printf have? (3)
- doesn’t specify how many arguments must be provided - there must be at least one argument - only the first argument has a strict type (it must be a string); all subsequent arguments may be of any type
74
If there’s a percent symbol inside the format, the printf considers it a ... on how to proceed with the arguments following the format. The first hint refers to the ... argument after the format, the second to the ..., etc. (but there are some exceptions to this simple rule).
hint, first, second
75
What is a specifier?
~ % joined with some other character
76
... specify that the following argument is of type int.
%d or %i
77
What does %x specify?
- the following argument is of type int and expressed as a hexadecimal number
78
What does %o specify?
- specifies that the corresponding argument is a value of type int and should be presented as a fixed-point octal number
79
... (as in ...) specifies that the corresponding argument is a value of type int or char and should be presented as a ...
%c, char, character
80
What is the specifier called that specifies that the corresponding argument is a value if type float presented as a floating-point number.
%f
81
If the % sign is a specifier, how do you display a percent sign normally?
- two percent signs %% mean only one of them will be displayed
82
Code the following: The text "This house was built in ... Its width is ..." is to be displayed. The two blanks contain two variables which need to be declared first, Year 1982 and Width 10.54. The computer then retrieved those variables and displays them in their proper place.
#include int main(void) { int Year; float Width; Year = 1982; Width = 10.54; printf("This house was built in %d. Its width is %f.", Year, Width); return(0); }
83
What happens when you code this snippet: printf("%d %d %d", i, j);
- there are more specifiers in the format than corresponding arguments - modern compilers recognise this error, older ones might not and will display a random value
84
What happens when you code this snippet: (3) printf("%d", i, j);
- there are fewer format specifiers than arguments - will not cause an error, the argument with the missing specifier will simply not be displayed - compiler might point out missing specifier
85
What happens when you code this snippet: printf("%d", i, j);
- there are fewer format specifiers than arguments - will not cause an error, the argument with the missing specifier will simply not be displayed - compiler might point out missing specifier
86
What happens when you code this snippet: int i; i = 100; printf("%f", i);
- specifier provides a different type to corresponding argument - if compiler doesn't notice mismatch, a random number will be displayed
87
What happens when you code this snippet: (3) char c; c = '?'; printf("%d", c);
- variable is declared as a char, specifier demands an int - char is treated as int, so this won't cause an error - printf will output the ASCII code of that character which was used as the corresponding argument
88
Encoding all data needed inside the source code is called ...
hard coding
89
What function similar to printf allows the user to enter data?
scanf
90
What are the differences between printf and scanf?
- scanf requires that the variable in which the user data is stored must be explicitly specified (no formulas)
91
How can you calculate the squareroot of a value?
EITHER value * value OR sqrtf(value)