C Style Guide Flashcards

1
Q

Keywords 1: Variable Definition

A

a quantity that may be changed according to the mathematical problem

int x;

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

Keywords 2: Variable Declaration

A

x = 10;

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

Keywords 3. Expressions

A

a combination of operands and operators

A+B;
A*B;
A==B:

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

Keywords 4. Operators

A

+, -, *, /, %, ++, –,
Relational Operators: ==, !=, >, > >=, <=,

Logical Operators: &&, ||, !(A &&B)
https://www.tutorialspoint.com/cprogramming/c_operators.htm

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

Keywords 5. Precedence table

A

https://www.cs.uic.edu/~i109/Notes/COperatorPrecedenceTable.pdf
operators will be performed in a different order of precedence, according to the precedence table.

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

Keywords 6. Sequence points

A

https://learn.microsoft.com/en-us/cpp/c-language/c-sequence-points?view=msvc-170

A point where all of the previous expressions must have been completed before continueing with the following expressions

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

Keywords 7. bits/bytes/wchar

A

wide char, meant to store UTF standard characters
bit, 1 and 0.
byte, 8 bits.

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

Keywords 8. Binary/octal/hexadecimal/decimal

A

don’t make me do it

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

Keywords 9. ASCII table

A

https://www.asciitable.com/

American Standard Code for Information Interchange,

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

Keywords 10. UTF

A

Unicode Transformation Format.
UTF-8: 9bit unicode conversion format.
UTF 65 = A
UTF 66 = B
etc

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

Keywords 11. Escape characters

A

backslash followed by uh, something.
https://www.ibm.com/docs/en/rdfi/9.6.0?topic=set-escape-sequences
\n creates a new line
\a creates an alert(?)
etc.

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

Expressions:

A

; - separator
int a; variable definition
void foo(int); function declaration
if(a > b){/* . . . /}; flow control statement, (a>b is an expression)
return, continue, break, for, do and while; flow control statements
void bar(void){/
. . . /}; function definition
struct definition: X{/
. . . */}
Alias Definition: typedef struct X X_t

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

Parts of Expressions

A

Type: int*, char, const, long, etc. including whether it is an l-value or non l-value
(l-value: expression representing a persistent memory location. can be accessed after the expression has been evaluated. & operator can only be used on l-value expressions)

Value: value of the expression

Side effect: something that can happen because of going through the expression at run time, but not needed in calculating the result.

Evaluation process: NOT a side effect.

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

Examples of Expressions

A

85
integer literal, type: non l-value int, value: 85

‘a’
character literal. Type: non l-value int

“abc”
String literal. Type: l-value array of 4 characters. value: when converted to a char*, value is the address of the first character

x
Variable, Type: l-value expression of the type x, value: value that x was initialized or assigned to.

-Evaluation process:

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

Sequence Points

A

Sequence Point: “A point in the code that guarentees the order of side effects”

Sequence Points: &&, ||, ? and ,
Sequence Point: ;

function call has two sequence points: one before it is called, and one after it returns. (must complete all side-effects preceding the parameter input, and return value.)

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

Exercise 1: Given the following code snippet, fill in the following:
int a = 3;
int foo();
a. a

A

a
Type: int(l-value), Value: 3,

17
Q

Q1 Why are coding conventions important

18
Q

Q2 What is the difference between a declaration and a definition?

19
Q

Q3 Where will you find declarations? Definitions?

20
Q

Q4 What is the difference between unspecified and undefined?

21
Q

Q5 What does the following code do?
int main()
{
int x = 20, y = 35;
x = y++ + x++;
y = ++y + ++x;
printf(“%d%d”, x, y);
}

22
Q

Q6 What does the following code do?
a[i] = i++;

23
Q

Q7 Which operators create expressions with side effects?

24
Q

Q8 Why is this important?

25
Q9 Where would you use the comma operator?
26
Q10 Why are the operators arranged in that specific order in the precedence table?
27
Q12 Will the following code compile? Will it run? Why?
28
Q13 Find / create 5 confusing expressions, and confuse your colleagues and mentors.
29
Q14 For each of these code snippets, is the bahaviour defined? Can you predict the order? Why?
30
15 Count all the expresisons and sub-expressions in every example. a-for each expression and sub-expression, identify its type, value, any side effects, evaluation process, and what could go wrong. b. Compile and run the code snippers. Do they do what you expected? c- Investigate implicit conversions and promotion rules for the last two snippers: