Null return null csse exam answers uqattic main argc
CSSE2310: 2012 exam answers
UQAttic.net
CSSE2310: 2012 exam answers
To get editing permissions, simply go to the and provide us with your Google Account address.
Style.
Head over to and click "Chat Now!". You'll find a chatroom full of students just like you. Talk about a revision document (like this one) or swap prep tips. If you have your own IRC client, point it to irc.uqattic.net, port 6667, channel #attic.
CSSE2310: 2012 exam answers
UQAttic.net
It’s not, they’re talking smack
head -42 words.txt | tail -1 ← thats how i did it and it works [+2]Alternatively, you can use `sed ‘42q;d’ words.txt` or `awk ‘NR==42’ words.txt`
I prefer `sed -n 42p words.txt` [+1]
D)Find all the lines in doc.txt which contain the word “fez” and store them in a file called cool.txt grep fez doc.txt > cool.txt [+1]
E) A file called words.txt has one word per line. Show how many different words in the file start with “A”.Question 2: C declarations
A) A long integer.
struct foo {
int fooInt[4];
char fooChar;
};
Note also the lowercase ‘foo’, as the question asks for ‘foo’, not ‘Foo’. (The style guide does not apply for the question, when it specifically asks for ‘foo’)This question is somewhat ambiguous, as there is no such thing as a ‘struct type’ in the C grammar. There are type identifiers and struct identifiers. Due to this, one interpretation of the question is that it is asking for a typedef struct, as below. If this is on an exam, seek clarification as to whether they are looking for a type (typedef) or just a struct declaration.
CSSE2310: 2012 exam answers
UQAttic.netFollowing from the previous answer, if the interpretation of 2C is asking for a typedef, then you would simply have: foo *foo;
H)
Ef
Should this be def, since in the if statement, they set d=true?No, answer is ‘ef’, reason is with the if statement, as soon as the first ‘true’ statement is reached with a logical or, the function continues and ignores (d=true).
So:
p+sizeof(int)=p+4=1000+4(int) = 1000 + 16 = 1016
See: for a detailed discussion.
J)
3
cnode* first = cl->head->next; // The first element in the list
cnode* current = cl->head; // Whatever we are currently checkingwhile ((current = current->next) != first) {
if (current->data == v) {
return current;
}
}
return NULL;
}
cnode* find(clist* cl, int v) {meant to be && currNode = currNode->next?
Question 5: Memory stuff
^ I agree
I also agree, except the tutor Simon said if the address divide 2^21 is exactly a number, the page it’s in is the page above it. Didn’t really understand why though. Making it 5, 5, 7, 6, 10. ^ well if you think about it, the page is going to span for lets say 100 hundred “lines”, which is from 0 - 99, so if you get something that is a whole number that is not 0, you’re on line “100” which is on the next page? Something like that, hope this explanation doesn’t confuse anyone further :X
^^ Third one can’t possibly be 7, since 1258912 < 1258929. If pages are indexed starting from 0, and they have 10 bytes, then address 10 will be on the 2nd page, i.e. page 1, so the formula floor(address/page size) holds perfectly for 0 indexed pages, hence the answer is 5, 5, 6, 6, 10 [BenM]According to Simon, the tutor: “b cannot segfault since it’s on the same page as a [page 5]”. So our program has access to page 5, but c is on page 6, which “may be invalid or you don’t have appropriate permissions”, so c is the answer - the first line which may segfault.
So should this be line 4 which causes segfault or line 5?????
A)
i)
To read 14, we need 2 reads (one for the pointer and one for the data). Since we have already cached the pointers used for 1026 and 1037, we only require 1 additional read for each. Total of 4 reads.
B)
All units in bytes.Could be factorised to:
[4096 * (13 + 1024 + 1024^2)] - [4096 * (12 + 2*1024 + 1024^2)] = 4,190,208 Bytes^^ Even more simply, change in max file size = (increase in block pointers - decrease in block pointers) * block size:
delta = (1024 - 1) * 4KB = 4092KB [BM][(13*4096) + (1*4096*1024) + (1*4096 * 1024^2) ] -
[(13*4096) + (0*4096*1024) + (2*4096 * 1024^2) ] = 4,290,772,992 Bytes^^ As for i:
delta = (1024^2 - 1024) * 4KB = 1024 * (1024 - 1) = 4092MB [BM]My answer was: It would allow faster access to the 14th block of the file since it would no longer require the level of indirection required by the single indirection pointer. [BM]
Would the 14th block still require the level of indirection required by the single indirection pointer? Because 14th block is still outside of the range [0, 13] mapped by direct blocks (it was [0, 12] before adding an additional direct pointer).CSSE2310: 2012 exam answers
UQAttic.netE)
Because the directory /usr/local/things probably doesn’t permit execution of files for donny.To expand on this - if donny doesn’t have +x rights on the directory /usr/local/things, he’s not allowed to go through it to access any of its contents, even if /usr/local/things/program has a+rwx.
Question 8: Fork stuff
A)
a
B)
C)
I’m assuming this question means “when is WIFEXITED false?”. A process won’t have a proper return value if a signal ended the process, although it will return some numbers depending on the signal which caused it to terminate (like 139 for segfault).
B)
Catflap is gateway (= router?) for entire network?
To send a UDP packet we need access to the DNS server? So must go through Savanna. Also need to go through the main gateway (Catflap) and subnet gateway (Forest).
E)
G)
|
||
---|---|---|
|
||
|
||
|
||
|
||
|
Question 10: More C programming
// Now sort array
for(int i = 1; i < size; ++i) {
for(int j = 0; j < size - i; ++j) {
temp = realloc(temp, strlen(array[j]) * sizeof(char));
// If the elements are backwards
if(strcmp(array[j], array[j+1]) < 0) {
// put element j in a temp string
temp = realloc(temp, strlen(array[j]) * sizeof(char));
strcpy(temp, array[j]);
// put element j+1 in element j
array[j] = realloc(array[j], strlen(array[j+1])*sizeof(char)); strcpy(array[j], array[j+1]);
// put the temp str into element j + 1
array[j+1] = realloc(array[j+1], strlen(temp) * sizeof(char)); strcpy(array[j+1], temp);
} |
|
---|
for (i = 0; i < size; i++) {
sorted[i] = (char *)arr[i];
}
for (i = 1; i < size; i++) {
for (j = 0; j < (size - 1); j++) {
if (strcasecmp(sorted[j], sorted[j+1]) > 0) { temp = sorted[j];
sorted[j] = sorted[j+1];
sorted[j+1] = temp;
}
}
}
return sorted;
}^this above solution doesn’t actually use the out most for loop(i): perhaps a better version of this code would be the folllowing.(it also creates a copy of the array).
CSSE2310: 2012 exam answers
UQAttic.netAnother soln:
char** arrsort(int size, char** array){
//swap
for (int i = 0; i < size; i++){
for (int j = i; j < size; j++){
if (strcmp(array[j], array[i]) < 0){ char * temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
//copy
char ** copy = malloc(sizeof(char *)*size);
for (int i = 0; i < size; i++){
copy[i] = malloc(strlen(array[i])*sizeof(char)); copy[i] = strcpy(copy[i], array[i]);
}
return copy;
}
:execlp("/bin/usr/sort", “sort”, NULL);
}
}Not sure why the above outputs garbage, but I rewrote it slightly and it works fine: [BM]
close(fd1[READ]);
close(fd2[WRITE]);for (int i = 0; i < size; ++i) {
fprintf(toSort, "%s\n", arr[i]);
}CSSE2310: 2012 exam answers
UQAttic.netword = realloc(word, buf_size * sizeof(char)); }
word[word_size++] = buf;
}//execlp("/bin/usr/sort", "sort", NULL);
execlp("sort", "sort", NULL);
}return NULL;
}