C Programming: Data Types, Memory Management, and Structures

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/49

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

50 Terms

1
New cards

Which data type typically uses 4 bytes in C?

int

2
New cards

What does the sizeof operator return?

The size in bytes of a variable or data type.

3
New cards

Which of the following is a valid variable name: 3value, #amount, value_3, or float?

value_3

4
New cards

After int x = 5; x++; ++x; what is the value of x?

7

5
New cards

Which format specifier is used for a double?

%lf

6
New cards

What does the condition if (a != b) mean?

a is not equal to b

7
New cards

What is wrong with the comparison 0 <= x <= 10?

You cannot chain comparisons; must use x >= 0 && x <= 10.

8
New cards

Which loop always executes at least once?

do-while loop

9
New cards

What does the loop for (int i = 0; i < 3; i++) printf("%d ", i); print?

0 1 2

10
New cards

What is the correct general form of a function prototype?

returnType functionName(parameters);

11
New cards

What is the return type of void printResult(int num);

void

12
New cards

Which statement about arrays is true?

All elements must be the same data type.

13
New cards

What does printf("%d", a[2]); output for int a[] = {1,2,3,4,5};?

3

14
New cards

In int table[3][4], how many rows are there?

3

15
New cards

Which function copies a C-string?

strcpy

16
New cards

What does strcmp("Dog", "Cat") return?

A positive value (since "Dog" > "Cat")

17
New cards

What is a pointer?

A variable that stores a memory address.

18
New cards

Which operator gives the address of a variable?

&

19
New cards

What does printf("%d", p); print if int x = 10; int p = &x;?

10

20
New cards

What does dereferencing a pointer mean?

Accessing the value stored at the pointer's memory address.

21
New cards

Which pointer initialization is valid?

int *p = &x;

22
New cards

What pointer action causes a segmentation fault?

Dereferencing an uninitialized pointer.

23
New cards

Pointer arithmetic increases the pointer by what?

The size of the pointee's data type.

24
New cards

Which library is required for malloc?

25
New cards

Which function allocates heap memory?

malloc

26
New cards

What does malloc(sizeof(int)) return?

A pointer to allocated memory for one int.

27
New cards

After calling free(ptr), what should you do?

Set the pointer to NULL.

28
New cards

What is a memory leak?

When allocated heap memory is not freed.

29
New cards

Which symbol accesses a struct member through a pointer?

->

30
New cards

Which is a correct struct declaration?

struct { int a; int b; } s;

31
New cards

What is wrong with struct point p = {5}; for a struct with two ints?

Must supply both values or use designated initialization.

32
New cards

When passing a struct to a function, what happens?

A full copy of the struct is passed.

33
New cards

Arrays decay into what when used in expressions?

Pointers (addresses)

34
New cards

What does int *ptr = NULL; mean?

ptr intentionally points to no valid memory.

35
New cards

Which scanset reads until newline?

%[^\n]

36
New cards

Which describes heap memory?

Memory dynamically allocated and manually managed by the programmer.

37
New cards

What happens if you don't free heap memory?

A memory leak occurs.

38
New cards

What is wrong with:

int *p;

*p = 10;

p is uninitialized and points nowhere.

39
New cards

Which scanf version reads strings with spaces?

scanf("%[^\n]", name);

40
New cards

What does int *matrix = malloc(5 sizeof(int*)); allocate?

Space for 5 row pointers (not full matrix yet)

41
New cards

Match term: Memory created at runtime using programmer control.

Dynamic allocation

42
New cards

Match term: A variable that holds a memory address.

Pointer

43
New cards

Match term: Releases heap memory.

free

44
New cards

Match term: Loop that always executes at least once.

do-while loop

45
New cards

Match term: Provides function's return type + parameters before definition.

Function prototype

46
New cards

Match term: Accessing value stored at an address.

Dereference

47
New cards

Match term: Creates a copy of a C-string.

strcpy

48
New cards

Match term: Reserves memory on the heap.

malloc

49
New cards

Match term: A collection of same-type elements stored contiguously.

Array

50
New cards

Match term: A user-defined grouping of mixed-type variables.

Struct