Quick drills
One-line questions for the last few minutes before the exam. Answer in your head, then tap a question to check yourself.
Linux Module 1
1Print the full path of the directory you're in.
pwd(print working directory)2From anywhere, go back to your home directory.
cdon its own (orcd ~)3Read a long file one screen at a time.
less notes.txt: Space for the next page,qto quit.moreworks too.4On one line, run
makeand thenls, runninglseven ifmakefails.make ; ls. With&&instead,lswould be skipped after a failure.5What does
ls -lshow forsecretafterchmod 700 secret?-rwx------: the owner can read, write and run it; the group and others get nothing.6Make a gzip-compressed archive
hw.tar.gzof the directoryhw.tar -czvf hw.tar.gz hw:ccreates,zcompresses, and the archive's name comes right afterf, before the folder.7In vim's Command Mode, undo the last change. Then, after searching with
/main, jump to the next match.uundoes.njumps to the next match (Ngoes back one).
Data representation Module 2
8
0xFFin decimal?255 (15 × 16 + 15)
9
1010 1010(binary) in hexadecimal?0xAA: each group of 4 bits,1010, is A.1045 as 8-bit binary?
0010 1101(32 + 8 + 4 + 1)11−1 as an 8-bit two's complement integer?
1111 1111(0xFF): flip0000 0001to1111 1110, then add 1.12The largest value a 16-bit unsigned integer can hold?
65,535, which is 2¹⁶ − 1.
13How many bits does one hex digit stand for? How many hex digits make one byte?
4 bits per hex digit, so 2 hex digits per byte.
C basics Module 3
14In C, what are
7 / 2and7 % 2?3 and 1. Dividing two
ints drops the fraction;%gives the remainder.15
(double) 7 / 2or(double) (7 / 2): which one is 3.5?(double) 7 / 2is 3.5. The other divides as integers first and gives 3.0.16What does
printf("[%5.1f]\n", 3.14159);print?[ 3.1]: one decimal place, padded on the left with two spaces to a width of 5.17After
int a = 5; a *= 2 + 1;what isa?15.
a *= 2 + 1meansa = a * (2 + 1).18What is
'7' - '0'?7, as an
int. The digit characters are next to each other in ASCII, so this turns a digit character into its number.19How many times does the body of
do { ... } while (0);run?Once. A
do-whileruns its body before it checks the condition.
Functions and arrays Module 4
20For
int temps[12];what issizeof(temps) / sizeof(temps[0])?12: the array is 48 bytes, and each
intis 4.21What return type does a function that returns nothing have?
void22Where does a function's prototype go, and how does it end?
Above
main(or in a header file), ending with;. It must match the definition's return type and parameters.23What are the valid indexes of
int scores[8]?0 to 7.
scores[8]is past the end: C doesn't stop you, but it's undefined behavior.
Structs and pointers Module 5
24
p_s->nameis short for what?(*p_s).name. The parentheses matter, because.binds tighter than*.25With
int a[3] = {4, 5, 6};andint *p = a;what are*(p + 2)andp[1]?6 and 5.
p[i]means*(p + i).26Which
printfspecifier prints an address?%p27On Zeus, how big is a pointer to a
char? To a large struct?8 bytes either way. A pointer holds an address, whatever it points to.
28Why does
sscanf(line, "%d", &n)need the&?sscanfhas to store the number inn, so it needsn's address. Passingnitself would only give it a copy of the value.
Strings, heap, gdb Module 6
29
strlen("hello"), andsizeof(s)forchar s[] = "hello";?5 and 6.
sizeofcounts the'\0'at the end;strlendoesn't.30What does
strcmpreturn when the two strings are equal?0. That's why the test is
strcmp(a, b) == 0, nota == b, which compares addresses.31Two differences between
malloc(n * sizeof(int))andcalloc(n, sizeof(int))?calloctakes the count and the size separately, and it fills the memory with zeros.mallocleaves whatever was there.32The command that checks
./progfor memory leaks?valgrind --leak-check=full ./prog33In gdb: show the chain of calls that led to where you're stopped, then keep running to the next breakpoint.
backtrace(bt), thencontinue(c).