Bits, Bytes, and Logic
All about C
Advanced C
Makefiles
Memory
100

Hexadecimal 0x6c is ____ in binary?
A. 01101010₂
B. 01101011₂
C. 01101100₂
D. 01100011₂

C. 01101100₂

100

What is printed when this C code fragment runs?
A. 121
B. 12
C. 1
D. 1212

int i = 0;

while (1) {

    printf("1");

    if (i > 0) break;

    printf("2");

    ++i;

}

A. 121

100

What is printed by the C code snippet below?
(The ␣ character represents a space character.)

printf("%9.2f", "123.45");

A. 123.45
B. 123.45␣␣␣
C. ␣␣␣123.45
D. 123.45000

C. ␣␣␣123.45

Recall: %9.2f means 

- total field width: 9 characters

- 2 digits after the decimal

- "123.45" is 6 characters, so it needs 3 leading spaces to make it 9 total.

100

What are the meanings of each of these automatic variables?
$^

$@

$<

$^ - All prerequisites

$@ - The target

$< - The first prerequisite


100

What are the two major differences between malloc() and calloc()?

1.  calloc() initializes memory as 0, and malloc() leaves it uninitialized

2. malloc() takes in 1 argument - number of bytes, while calloc() takes in 2 arguments - number of elements and size of each element

200

The binary number 10111110₂ has which decimal value?
A. -67
B. -68
C. -66
D. 125

C. -66

200

Which C statement(s) below increment the value of the variable x?
(check all that apply)

A. x =+ 1;
B. ++x;
C. x = x + 1;
D. x += 1;
E. x++;

B. ++x;

C. x = x + 1;

D. x += 1;

E. x++;

200
  1. Why do we use an int type variable for ch instead of a char type variable?

int ch = getchar();

A. The code is incorrect, and ch should be declared as a char.
B. getchar() can return any of the 256 char values, but it also could return the special value EOF.

B. getchar() can return any of the 256 char values, but it also could return the special value EOF.

200

What is the name of the file which is used to direct compilation and linking of your C program into an executable binary?
A. cformat
B. hello.c
C. Makefile
D. README.md

C. Makefile

200

Are function arguments in C passed by reference or passed by value?

What does this mean?

Pass by value - 

  • A copy of the variable is passed to the function.

  • The function cannot modify the original variable directly

Therefore we use pointers to emulate pass by reference

300

What is the result of the following C expression?

int x = 12 ^ 5;

printf("%d\n", x);|

A. 9
B. 7
C. 1
D. 8

             1100

^ (XOR) 0101

           = 1001  → A. 9 in decimal

300

Which of the following keywords should you use to immediately exit from an enclosing loop?
A. break
B. exit
C. goto
D. continue

A. break

300

A. True. B. False.
This expression returns a non-zero value.

islower('s')

A. True

300

True or False

When compiling a large project with multiple files that depend on one another, each .c file must be compiled to its own executable binary

False

They are compiled to object (.o) files

300

What causes a Segmentation Fault to occur?

A Segmentation Fault occurs when a program tries to access memory it's not allowed to, such as:

- Dereferencing a NULL or uninitialized pointer

- Writing to read-only memory

- Accessing out of bounds memory

- Trying to use already freed memory

400

Which of the following expressions checks whether the 4th bit from the right of variable x is set to 1?
A. x & 0x08
B. x | 0x08
C. x ^ 0x08
D. x && 0x08

A. x & 0x08

400

Which of the following is not considered a top-test loop?
A. do-while
B. for
C. while
D. All of them are top-test loops.

A. do-while

400
  1. A. True. B. False.
    In the C programming language, this is how to correctly declare that a function fun() has two parameters of type double and returns a value of type double.

double fun(double double)


B. False

Should be something like

double fun(double a, double b)


400

When borrowing function declarations from another file, what is the type of file that must be included at the top of our main.c?

header (.h) files

ex)

#include "linkedlist.h"

400

What is " x ->next" shorthand for?

What is it doing?

(*x).next

500

The operations of this expression are performed in which order?
A. ==  !=  &  |  &&
B. ==  !=  |  &  &&
C. |  ==  &&  &  !=
D. |  &  ==  !=  &&

a | 8 == 0 && b & 8

A. ==  !=  &  |  &&

500

A. True.
B. False.

The following for loop syntax is valid and produces an infinite loop.

for (;;) {

    printf("Loop infinitely?\n");

}


B. False.

500

A. True. B. False.
'A' is an integer.

A. True

500

How do you construct a rule using

1. target

2. prerequisites

3. command

in a Makefile?

target: prerequisites

      commmand

500

What is missing from these struct declarations?

typedef struct node {
    int data;
    ___(1)__ next;
} Node;

typedef struct __(2)__ {
    struct linkedlist* head;
    struct linkedlist* tail;
    int length;
} LL;

1. struct node*

2. linkedlist