Programming And Algorithms

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/61

flashcard set

Earn XP

Description and Tags

Term 1

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

62 Terms

1
New cards

What is the difference between Declarative and Imperative programming?

Declarative describes WHAT you want (properties); Imperative describes HOW to construct it (step-by-step).

2
New cards

What is Functional Decomposition?

Breaking a complex problem down into smaller, simpler steps/functions to solve the bigger problem.

3
New cards

Who invented the C programming language and when?

Dennis Ritchie at AT&T Bell Labs, around 1972.

4
New cards

What does the -Wall gcc flag do?

It shows all compiler warnings.

5
New cards

What are the four basic variable types in C?

char, int, float, double.

6
New cards

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.

7
New cards

What is the difference between signed and unsigned variables?

Unsigned can only hold non-negative numbers; Signed can hold both positive and negative.

8
New cards

What operator returns the storage size of a variable?

sizeof().

9
New cards

What are the two main storage classes in C?

Automatic (local, destroyed on exit) and Static (exists for entire program duration).

10
New cards

What is the scope of a Local variable?

Only accessible within the block (curly braces) where it is declared.

11
New cards

What happens if a local variable has the same name as a global one?

The block sees the LOCAL variable (the global is hidden).

12
New cards

What is "Pass by Value"?

The function receives a COPY of the argument. Changing the parameter does not change the original variable.

13
New cards

What does 'return 0' in main() signify?

The program exited with no errors.

14
New cards

What printf specifier is used for a decimal integer?

%d.

15
New cards

What printf specifier is used for a string?

%s.

16
New cards

What is the difference between a while and do-while loop?

'while' checks condition BEFORE execution; 'do-while' executes at least once before checking.

17
New cards

What are the three parts of a for loop?

Initialization, Condition, Update (e.g., i=0; i<10; i++).

18
New cards

What does the break statement do in a loop?

Immediately exits the current loop.

19
New cards

What does the continue statement do in a loop?

Jumps to the next iteration of the loop.

20
New cards

How are TRUE and FALSE represented in C?

FALSE is 0; TRUE is any non-zero value.

21
New cards

What is "Short-circuit evaluation"?

Evaluation of && or || stops as soon as the result is known (e.g., if first part of && is false).

22
New cards

What is the switch statement used for?

Testing an expression against multiple constant values (cases).

23
New cards

What is the difference between i++ and ++i?

i++ uses value then increments (Postfix); ++i increments then uses value (Prefix).

24
New cards

What does the & operator do (in bitwise context)?

Bitwise AND.

25
New cards

What does the && operator do?

Logical AND.

26
New cards

What is the Ternary Operator syntax?

condition ? valueiftrue : valueiffalse.

27
New cards

Which C standard is used in COMP1005?

ANSI C (C89/C90).

28
New cards

Are // comments allowed in ANSI C?

No, you must use /* … */.

29
New cards

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).

30
New cards

In a nested if-else, which 'if' does a dangling 'else' belong to?

The nearest previous 'if' that doesn't already have an 'else'.

31
New cards

What are the escape sequences for Newline, Tab, and Backspace?

\n, \t, \b.

32
New cards

What is the value of an uninitialized local variable?

Indeterminate (random/garbage).

33
New cards

Does C check array bounds?

No. Accessing outside bounds causes undefined behavior.

34
New cards

How are static arrays initialized by default?

To zero.

35
New cards

How are automatic (local) arrays initialized by default?

They contain indeterminate/garbage values.

36
New cards

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.

37
New cards

How does C determine the end of a string?

It looks for the NUL character ('\0').

38
New cards

What does the & operator do (in pointer context)?

Address-of operator (returns memory address of variable).

39
New cards

What does the * operator do (in pointer context)?

Dereference operator (accesses value at the address).

40
New cards

What is a Segmentation Fault?

A runtime error caused by attempting to access illegal memory.

41
New cards

What are the four program memory segments?

Text (code), Data (globals), Stack (locals), Heap (dynamic).

42
New cards

What is the difference between malloc() and calloc()?

malloc allocates uninitialized memory; calloc allocates zero-initialized memory.

43
New cards

What must you do with malloc'd memory when finished?

Free it using free() to avoid memory leaks.

44
New cards

What are the three standard I/O streams?

stdin, stdout, stderr.

45
New cards

Why does scanf need '&' before variables?

It requires the address to modify the variable (pass by reference).

46
New cards

What does fopen mode "w" do?

Opens for writing; truncates file to zero if it exists, creates new if not.

47
New cards

What are the four stages of compilation?

Preprocessing, Compilation, Assembly, Linking.

48
New cards

What does the Preprocessor do?

Handles directives (#include, #define), removes comments.

49
New cards

What are argc and argv?

argc is argument count; argv is array of argument strings.

50
New cards

What is "Pass by Reference"?

Passing a pointer to a variable so the function can modify the original.

51
New cards

What does typedef do?

Creates an alias for an existing type (does not create a new type).

52
New cards

Difference between struct and union memory?

Struct size is sum of members; Union size is size of largest member (shared memory).

53
New cards

What operator accesses members via a pointer?

The arrow operator (->).

54
New cards

What is a Self-Referential Structure?

A struct containing a pointer to a struct of the same type (used in Linked Lists).

55
New cards

What marks the end of a Linked List?

The next pointer is NULL.

56
New cards

What are Include Guards?

Preprocessor directives (#ifndef) used to prevent double inclusion of headers.

57
New cards

What is the time complexity of Binary Search?

O(log n).

58
New cards

What is the prerequisite for Binary Search?

Data must be sorted.

59
New cards

What are the two parts of recursion?

Base case and Recursive step.

60
New cards

What is Stack Overflow?

When recursion goes too deep and fills the stack memory.

61
New cards

What is Reverse Polish Notation (RPN)?

A mathematical notation where operators follow operands (e.g., 3 4 +).

62
New cards

What data structure is used for RPN?

A Stack (LIFO).