1/61
Term 1
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
What is the difference between Declarative and Imperative programming?
Declarative describes WHAT you want (properties); Imperative describes HOW to construct it (step-by-step).
What is Functional Decomposition?
Breaking a complex problem down into smaller, simpler steps/functions to solve the bigger problem.
Who invented the C programming language and when?
Dennis Ritchie at AT&T Bell Labs, around 1972.
What does the -Wall gcc flag do?
It shows all compiler warnings.
What are the four basic variable types in C?
char, int, float, double.
What are the rules for valid variable names in C?
Must begin with a letter (or underscore), followed by letters, digits, or underscores. No reserved words.
What is the difference between signed and unsigned variables?
Unsigned can only hold non-negative numbers; Signed can hold both positive and negative.
What operator returns the storage size of a variable?
sizeof().
What are the two main storage classes in C?
Automatic (local, destroyed on exit) and Static (exists for entire program duration).
What is the scope of a Local variable?
Only accessible within the block (curly braces) where it is declared.
What happens if a local variable has the same name as a global one?
The block sees the LOCAL variable (the global is hidden).
What is "Pass by Value"?
The function receives a COPY of the argument. Changing the parameter does not change the original variable.
What does 'return 0' in main() signify?
The program exited with no errors.
What printf specifier is used for a decimal integer?
%d.
What printf specifier is used for a string?
%s.
What is the difference between a while and do-while loop?
'while' checks condition BEFORE execution; 'do-while' executes at least once before checking.
What are the three parts of a for loop?
Initialization, Condition, Update (e.g., i=0; i<10; i++).
What does the break statement do in a loop?
Immediately exits the current loop.
What does the continue statement do in a loop?
Jumps to the next iteration of the loop.
How are TRUE and FALSE represented in C?
FALSE is 0; TRUE is any non-zero value.
What is "Short-circuit evaluation"?
Evaluation of && or || stops as soon as the result is known (e.g., if first part of && is false).
What is the switch statement used for?
Testing an expression against multiple constant values (cases).
What is the difference between i++ and ++i?
i++ uses value then increments (Postfix); ++i increments then uses value (Prefix).
What does the & operator do (in bitwise context)?
Bitwise AND.
What does the && operator do?
Logical AND.
What is the Ternary Operator syntax?
condition ? valueiftrue : valueiffalse.
Which C standard is used in COMP1005?
ANSI C (C89/C90).
Are // comments allowed in ANSI C?
No, you must use /* … */.
What is the difference between High-Level and Low-Level languages?
Low-level is close to hardware (efficient, hard to write); High-level is abstract (portable, easier to write).
In a nested if-else, which 'if' does a dangling 'else' belong to?
The nearest previous 'if' that doesn't already have an 'else'.
What are the escape sequences for Newline, Tab, and Backspace?
\n, \t, \b.
What is the value of an uninitialized local variable?
Indeterminate (random/garbage).
Does C check array bounds?
No. Accessing outside bounds causes undefined behavior.
How are static arrays initialized by default?
To zero.
How are automatic (local) arrays initialized by default?
They contain indeterminate/garbage values.
What is the difference between char a[]="x" and char *p="x"?
a[] is an array you can modify; *p points to a read-only string constant.
How does C determine the end of a string?
It looks for the NUL character ('\0').
What does the & operator do (in pointer context)?
Address-of operator (returns memory address of variable).
What does the * operator do (in pointer context)?
Dereference operator (accesses value at the address).
What is a Segmentation Fault?
A runtime error caused by attempting to access illegal memory.
What are the four program memory segments?
Text (code), Data (globals), Stack (locals), Heap (dynamic).
What is the difference between malloc() and calloc()?
malloc allocates uninitialized memory; calloc allocates zero-initialized memory.
What must you do with malloc'd memory when finished?
Free it using free() to avoid memory leaks.
What are the three standard I/O streams?
stdin, stdout, stderr.
Why does scanf need '&' before variables?
It requires the address to modify the variable (pass by reference).
What does fopen mode "w" do?
Opens for writing; truncates file to zero if it exists, creates new if not.
What are the four stages of compilation?
Preprocessing, Compilation, Assembly, Linking.
What does the Preprocessor do?
Handles directives (#include, #define), removes comments.
What are argc and argv?
argc is argument count; argv is array of argument strings.
What is "Pass by Reference"?
Passing a pointer to a variable so the function can modify the original.
What does typedef do?
Creates an alias for an existing type (does not create a new type).
Difference between struct and union memory?
Struct size is sum of members; Union size is size of largest member (shared memory).
What operator accesses members via a pointer?
The arrow operator (->).
What is a Self-Referential Structure?
A struct containing a pointer to a struct of the same type (used in Linked Lists).
What marks the end of a Linked List?
The next pointer is NULL.
What are Include Guards?
Preprocessor directives (#ifndef) used to prevent double inclusion of headers.
What is the time complexity of Binary Search?
O(log n).
What is the prerequisite for Binary Search?
Data must be sorted.
What are the two parts of recursion?
Base case and Recursive step.
What is Stack Overflow?
When recursion goes too deep and fills the stack memory.
What is Reverse Polish Notation (RPN)?
A mathematical notation where operators follow operands (e.g., 3 4 +).
What data structure is used for RPN?
A Stack (LIFO).