PL Week 3 Material

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/36

flashcard set

Earn XP

Description and Tags

INCOMPLETE

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

37 Terms

1
New cards

“C is a middle-level programming language.”

Briefly explains what this means.

C combines features of low-level (memory, hardware access) & high-level (functions, modular code) programming languages.

2
New cards

“C is structured and modular.”

Briefly explains what this means.

C uses functions to divide programs into manageable blocks of code, which makes debugging reuse easier.

3
New cards

“C has efficient I/O (input/output).”

Briefly explains what this means.

  • scanf() for direct access to input operations

  • printf() for direct access to output operations

4
New cards

scanf() uses ____________ input, which can affect…

scanf() uses buffered input, which can affect how strings and newlines are handled.

5
New cards

You should always check return values from scanf() to ensure….

You should always check return values from scanf() to ensure…. input was correctly received.

6
New cards

Mismatching format specifiers (e.g., %d for a float) may cause ____________ behaviour.

Mismatching format specifiers (e.g., %d for a float) may cause undefined behaviour.

7
New cards

T or F: C is a case-sensitive language.

True

8
New cards

T or F: C treats Variable and variable as different identifiers.

True because C is case-sensitive

9
New cards

Every _________ in C must end with a semi-colon.

Every statement in C must end with a semi-colon.

10
New cards

Name 2 things curly braces are used for in C.

  1. Used to define blocks of code, especially for if, loops, and functions.

//Example
if (x > 0) {
    printf("Positive\n");
    x = x - 1;
}

(2) Helps group multiple statements.

//Example
#include <stdio.h>

int main() {
    int x = 10;

    if (x > 5) {
        printf("x is greater than 5\n");
        x = x - 1;
        printf("x is now %d\n", x);
    }

    return 0;
}

//Without { }, only one statement would be part of the if.

//With { }, it groups multiple statements as one block under the if.

11
New cards

T or F: In C, a main() function is NOT mandatory.

False.

12
New cards

What are the two forms of main() function accepted in C?

//Opt 1
int main() 

//Opt 2 
void main()  // non-standard, but accepted in many compilers

13
New cards

(a) Name the 3 categories of data types.

(b) Then name the main types within each category, their size, and their range.

(1) BASIC (PRIMARY)

Type

Size

Range

int

2 bytes

-32,768 to 32,767

char

1 byte

-128 to 127

float

4 bytes

~±3.4 × 10⁻³⁸ to 10³⁸

double

8 bytes

~±1.7 × 10⁻³⁰⁸ to 10³⁰⁸

(2) MODIFIED

Type

Size

Description

unsigned int

2

0 to 65,535

long int

4

Larger range than int

short int

2

Smaller range

unsigned char

1

0 to 255

(3) DERIVED

  • Arrays

  • Pointers

  • Structures

  • Unions

14
New cards

(a) What is a pointer?

(b) Syntax?

(a) A pointer is a variable that stores the memory address of another variable.

(b) Syntax:

//Syntax

int x = 10;

int *p = &x; // 'p' holds the address of x

15
New cards

Operator

&

What’s its meaning?

Operator

Meaning

&

"Address of" operator

16
New cards

Operator

*

What’s its meaning?

INCOMPLETE

17
New cards

In order to use a pointer, you must always..

Initialize the pointer before using it.

18
New cards

Uninitialized pointers can cause…

INCOMPLETE

19
New cards

Which types of statements in C govern the flow of execution?

🔹 if, if-else, and nested if-else

20
New cards

Describe what each is used for in 1 sentence:

(a) if, if-else, and nested if-else

(b) switch Statement

(a) if, if-else, and nested if-else

Used to selectively execute code based on one or more Boolean conditions, with nested if-else handling multiple layered decisions.

Example:

if (x > y) {
  printf("x is greater");
} else {
  printf("y is greater");
}

(b) switch Statement

Used for multi-way branching, efficiently executing code based on the value of a single expression (usually an integer or enum).

Example:

  printf("y is greater");
}

(c) while Loop

  • Unknown number of iterations

  • Executes a block of code repeatedly as long as the condition is true, checking the condition before the first iteration.

(d) do-while Loop

  • Executes a block of code at least once, and then continues looping while the condition remains true (condition is checked after the loop body).

  • A

(e) for Loop

21
New cards

Describe what each is used for in 1 sentence. Then specify when the loop condition is evaluated — that is, whether the loop checks the condition before (entry) or after (exit) executing the loop body.

(a) while Loop

(b) do-while Loop

(c) for Loop

Loop Type

Entry/Exit

Used For

while

Entry

Unknown iterations (check before)

do-while

Exit

At least one iteration guaranteed

for

Entry

Count-controlled iterations

22
New cards

Briefly what “Jump” statements do:

(a) break

(b) continue

🔹 Jump Statements

  • break: Exit loop or switch

  • continue: Skip to next iteration

23
New cards
24
New cards
25
New cards
26
New cards
27
New cards
28
New cards

&&

(a) Type of operator?

(b) Function

(a) Type: Logical operator

(b) Function:

  • Used to combine two Boolean conditions.

  • The result is true (1) only if both conditions are true; otherwise, it evaluates to false (0).

if (x > 0 && x < 10)
{
    printf("x is between 1 and 9\n");
}

29
New cards
30
New cards
31
New cards
32
New cards
33
New cards
34
New cards
35
New cards
36
New cards
37
New cards