ACTUAL Exam Questions and CORRECT
Answers
Lexical Rules - CORRECT ANSWER - 1. Identifiers. Names (programmers chosen) for
something of interest (variables, functions, methods, classes, etc.)
2. Keywords. names reserved by the language designer: if, switch, for, int, float, char, while, etc.
3. Operators. +, *, <, >=, !, &&, ||, etc.
4. Delimiters. , ; () {}
5. Literals. 5, 14.5, 'A', "Hello",
6. Comments. /* ... */, // ...
7. Putting together symbols, to create words
8. Variable names should start with a letter, '$', or '_'.
Syntactic Rules - CORRECT ANSWER - * Putting together words, to create sentences
Semantic Rules - CORRECT ANSWER - 1. Declaration and Unicity. Reviews for uniqueness
and that the variable has been declared before its usage.
2. Types. Reviews that the types of variables match the values assigned to them.
3. Array's indexes. Reviews that the indexes are integers.
4. Conditions. Reviews that all the expressions on the conditions return a boolean value.
5. Return Type. Reviews that the value returned by a method matches the type of the method.
6. Parameters. Reviews that the parameters in a method match in type and number with the
declaration of the method.
Syntactic vs. Semantic - CORRECT ANSWER - Syntactic is if the sentence follows the
correct format, semantic is if the sentence makes sense.
*(a + i) = a[i] - CORRECT ANSWER - Tricky Examples:
, *(a + (i + 1)) != *(a + i) + 1;
/*
This does not shift the letters over to the right by 1.
* e.g. *(a + (i + 1));
It increments the value of i by 1.
Meaning a String of "2020" would become "3131".
*/
*(*(a + i) + j) == a[i][j];
Lexical Errors in C Examples - CORRECT ANSWER - int 1dog; // Can't start with anything
except for a letter, '$', or a '_'.
int ch(um; // Using a delimiter.
char[] x = 'hello there"; // Must have matching quotations and properly closed quotations.
( ) { } [ ] each one is 1 word: '(' = 1 word and ')' = 1 word.
"==" is one word.
Syntactic Errors in C Examples - CORRECT ANSWER - (a1 / a2) = (c3 - c4) // Can't set
expressions equal to each other.
p4rd2 = (x + y) hi (a / z);
struct dog { } // Needs a semicolon afterwards.
if (1} { } // Doesn't match parentheses
Semantic Errors in C Examples - CORRECT ANSWER - x = 5; // Valid even if x hasn't been
declared.
while (5) {if (6) { }}
Default Declarations and Sizes of Data Types in C - CORRECT ANSWER - int x = signed
short int