-
Write a structure for date w/ month, day and year.
- struct date {
- int month;
- int day;
- int year;
- };
-
Change the structure 'struct date' to be just date.
typedef struct date date;
-
Declare a new variable of a structure date. Name it finsky
date finsky;
-
What is wrong with: struct date { int month; int day; int year; }
Forgot Semicolon at end of declaration.
-
How to you find the address of a variable?
&varName
-
Where do you define global structures in the program?
Outside of any function and first. (after #include)
-
What do you need to include to access type bool?
<stdbool.h>
-
Can you pass structures as arguments?
Yes. You can return structures too.
-
Is this correct? struct date today = {7,5,2006};
Yes
-
Is this correct? struct date today = {day = 7};
No. Need a . infront of day
-
Is this correct? today = (struct date) {9,25,1985};
Yes
-
What is an example of initializing a structure using a compound literal?
declaredVar = (StuctType) {1,50,1095};
-
How do you create the listNode structure?
- struct listNode {
- int value;
- listNode *next;
- };
-
How do you initialize a list?
- void initializeList() {
- head = NULL;
- numItems = 0;
- }
-
What is a pointer?
A var that contains a memory address.
-
What are pointers used for?
To access memory and manipulate addresses.
-
What is * operator used for?
Access pointed-To
-
Does * let you access the value stored in the pointer?
No! It lets you access the value stored in pointed to!
-
What is the unary address operator?
&
-
How do you assign a pointer?
*p = &var
-
How do you print a pointer value?
%u
-
Can you declare a void pointer?
Yes, void *p;
-
What is the structure Pointer Operator?
-> equivalent to (*pointer_to_structure).memberName
-
Which has preference -> or . ?
They are equal
-
What type is a pointer to a structure?
The same type as the structure
-
What is this? p->next
a structure with a pointer to it, referencing a member called next
-
What does getchar() do?
It reads a character from the keyboard.
-
How do you concatenate strings?
strcat(1,2)
-
How do you copy one string into another?
strcpy(designation, copied)
-
How do you count the number of characters in a string before \0?
strlen
-
What header file must be included to use calloc() and malloc()?
<stdlib.h>
-
What is the difference between calloc and malloc?
calloc initializes to zero.
-
what two arguments does calloc require?
number of objects, size of object
-
What do you need to remember to do with dynamically allocated memory?
Free it when your done! free(var);
-
What does calloc return?
A void pointer to a space in dynamic memory.
-
How do you print a tab character?
\t
-
How does Binary Search work?
Split in half, search half.
-
How many comparisons does Binary search require?
log(n)
-
When a programmer says log which base are they referring to?
2
-
How does Bubble sort work?
Compare adjacent, swap if necessary
-
Hoe does selection sort work?
Find largest item, and move to end.
-
How does insertion sort work?
Sorted region and unsorted. At each step move first unsorted into proper position
|
|