Structures
Pointers
ADTs and Unions
Standard I/O
Bitwise Operators
100

The following is the declaration syntax for a structure (design must be exact; names do not have to be)

struct [ tag] {

data_members

} [ vars ];

100

int a, *b, *c;

b = &a;

c = b;

What is the value returned by dereferencing c?

Unknown. No value was stored at the location of a, so we don't know what value is there.

100

What is a Abstract Data Type

A conceptual entity that consists of data and operations on that data. Is designed around the principle of separation of use from implementation.

100

What are the two types of i/o streams?

Binary and Text. 

100

What are the 6 bitwise operators (Four bitwise logical operators and two shift operators)

Bitwise logical operators:

AND ( & ), OR ( | ), XOR ( ^ ), Complement ( ~ )

Shift operators:

Left Shift ( << ) and Right Shift ( >> )

200

A structure is a ___________ collection, accessed by _______  _______ (fill in the three blanks)

heterogeneous

member name

200

Arrays are passed by reference. What does this mean?

When an array is passed to a function, what is actually passed is the address of the first element, i.e. a pointer to the first element. Follow up: How can you access the elements of the array? 

200

C is a ______ typed language and has ________ typing (Fill in the blanks)

Weakly typed; Static typing. What do each of these mean?
200

What is returned by the fread() and fwrite() binary stream i/o functions?

They return the number of items transferred. What does this mean?
200

printf("%d\n", 26 & 19);

what is the output of the above print statement;

18 

19ten = 10011two

26ten = 11010two

10011two & 11010two = 10010two

10010two = 18

300

define a type called myExample that redefines a structure that has the tag example and contained the following data members: an integer named a, a character named b, and a float named c

typedef struct example {

int a;

char b;

float c;

} myExample;

300

What does it mean to have a dangling pointer and what are the potential dangers?

A dangling pointer is a pointer that pointed to allocated memory, but the space was deallocated and the variable is left unchanged. This is dangerous because the pointer still points to the location in allocated memory that it originally did, so if you dereference that pointer, what is at that location is unknown. How can you prevent a dangling pointer?

300

union myData{

char c[8];

float f[2];

int i[2];

short s[4];

unsigned int u[2];

double d;

void *v;

};

What is the size in memory of the union above.

8 bytes. A union is the size of the largest data member.

300

What are the differences between Binary streams and Text streams

Binary streams take in and output raw bytes of data with no interpretation done Binary Files are unstructured.

 Text streams represent each byte of data as a character. Text files are structured with zero or more lines, each containing zero or more characters and ending with EOLN character sequence.

300

What is the difference between the Bitwise Operators and all other Operators in C?

The Bitwise Operators operate on each bit of a value individually, while all other operators perform operations on values as a collection of bits representing that value.

400

struct example contains an int named a, a char named b, and a float named c.

struct example var2;

var2 = {.c=12.5, 'x', 42};

These are the two errors with the code above.



Requires compound literal

Requires designated initializers

var2 = (struct example){ .c=12.5, .b='c', .a=42};

400

void my_function(int);

void (*alpha)(int);

1. alpha = &my_function;

2. alpha = &*****&my_function;

3. (*&**&alpha)(10);

Which of the above is an improper use of function pointers?

All of these are correct uses.

400

union data{

char c[1];

float f[1];

short s[1];

void *v;

} var1;

var1.c[0] = 'c';

printf("%c\ncool", var1.c[1]);

What is the result of the above print statement? 

This will not cause an error. If the bits in the union that var1.c[1] retrieves from can be represented as a valid printable character, that character will be printed and then 'cool' will be printed on the next line. Otherwise, nothing will be printed on the first line and 'cool' will be printed on the second line.

400

size_t fread( void *buffer, size_t length, size_t count, FILE *stream );

size_t fwrite( void *buffer, size_t length, size_t count, FILE *stream );

The above is the syntax for the fread() and fwrite() binary stream i/o functions. 

buffer - array of "items" in memory

length - size of each "item" (not size of array!)

count​​​​​​​ - number of "items" to read/write

stream - i/o steam to use

400

What is the difference between a right logical shift and right arithmetic shift?

A right logical shift always fills empty bits with zeros.

A right arithmetic shift fills empty bits with copies of the leftmost bit.

What about a left arithmetic shift?

500

struct stuff {

char c1;

long int li1;

char c2;

char arr[8];

char *c3;

double d1;

short s1;

};

This is the size in bytes that the structure above would take up in memory

56 bytes

500

int *var = (int *) calloc(5, sizeof(int));

var = (int*) realloc(var, 10*sizeof(int));

What is the potential problem with the above code?

1. You should always verify that the return from any of the memory allocation functions is not NULL. If it is NULL, you will have an error during reallocation.

2. If realloc returns NULL, you have just lost your pointer to your allocated memory. There is now no way to deallocate that memory. What should you do instead to prevent this from happening.

500

How does a Union work

All data members of a union share the same space. When a value is assigned to one of the data members, a section of the bits of the union are manipulated to represent that value based on the type of the data member that is assigned to. When a value is retrieved from the union using one of the data members, the type of that data member determines how many bits of union are selected and how those bits are represented.

500

What is the syntax for the i/o function that opens files and what does it do? 

FILE *fopen( const char *path, const char *mode );

This function opens the file in the path given via a system call. It then allocates & initializes FILE structure.

What can be passed as mode?

500

( y ^ y ) ^ y = ?

What is ?

( y ^ y ) ^ y = y

M
e
n
u