1/49
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Which data type typically uses 4 bytes in C?
int
What does the sizeof operator return?
The size in bytes of a variable or data type.
Which of the following is a valid variable name: 3value, #amount, value_3, or float?
value_3
After int x = 5; x++; ++x; what is the value of x?
7
Which format specifier is used for a double?
%lf
What does the condition if (a != b) mean?
a is not equal to b
What is wrong with the comparison 0 <= x <= 10?
You cannot chain comparisons; must use x >= 0 && x <= 10.
Which loop always executes at least once?
do-while loop
What does the loop for (int i = 0; i < 3; i++) printf("%d ", i); print?
0 1 2
What is the correct general form of a function prototype?
returnType functionName(parameters);
What is the return type of void printResult(int num);
void
Which statement about arrays is true?
All elements must be the same data type.
What does printf("%d", a[2]); output for int a[] = {1,2,3,4,5};?
3
In int table[3][4], how many rows are there?
3
Which function copies a C-string?
strcpy
What does strcmp("Dog", "Cat") return?
A positive value (since "Dog" > "Cat")
What is a pointer?
A variable that stores a memory address.
Which operator gives the address of a variable?
&
What does printf("%d", p); print if int x = 10; int p = &x;?
10
What does dereferencing a pointer mean?
Accessing the value stored at the pointer's memory address.
Which pointer initialization is valid?
int *p = &x;
What pointer action causes a segmentation fault?
Dereferencing an uninitialized pointer.
Pointer arithmetic increases the pointer by what?
The size of the pointee's data type.
Which library is required for malloc?
Which function allocates heap memory?
malloc
What does malloc(sizeof(int)) return?
A pointer to allocated memory for one int.
After calling free(ptr), what should you do?
Set the pointer to NULL.
What is a memory leak?
When allocated heap memory is not freed.
Which symbol accesses a struct member through a pointer?
->
Which is a correct struct declaration?
struct { int a; int b; } s;
What is wrong with struct point p = {5}; for a struct with two ints?
Must supply both values or use designated initialization.
When passing a struct to a function, what happens?
A full copy of the struct is passed.
Arrays decay into what when used in expressions?
Pointers (addresses)
What does int *ptr = NULL; mean?
ptr intentionally points to no valid memory.
Which scanset reads until newline?
%[^\n]
Which describes heap memory?
Memory dynamically allocated and manually managed by the programmer.
What happens if you don't free heap memory?
A memory leak occurs.
What is wrong with:
int *p;
*p = 10;
p is uninitialized and points nowhere.
Which scanf version reads strings with spaces?
scanf("%[^\n]", name);
What does int *matrix = malloc(5 sizeof(int*)); allocate?
Space for 5 row pointers (not full matrix yet)
Match term: Memory created at runtime using programmer control.
Dynamic allocation
Match term: A variable that holds a memory address.
Pointer
Match term: Releases heap memory.
free
Match term: Loop that always executes at least once.
do-while loop
Match term: Provides function's return type + parameters before definition.
Function prototype
Match term: Accessing value stored at an address.
Dereference
Match term: Creates a copy of a C-string.
strcpy
Match term: Reserves memory on the heap.
malloc
Match term: A collection of same-type elements stored contiguously.
Array
Match term: A user-defined grouping of mixed-type variables.
Struct