Midterm Solutions 2013

C it finds the last location of y in f zeros out that

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int pointer. (e) Nothing; you cannot find the size of an array. 7. The %s format specifier takes in a char* and prints until it finds a null character. What do the following two lines of code print? char *s = "uncharacteristic"; printf("%s",s+s[7]-s[6]); (a) "uncharacteristic" (b) "ncharacteristic" (c) "characteristic" (d) "haracteristic" (e) Nothing; the address is not valid 8. What does the following method do? char * bizarre(char *f,char y) { char *h = f; for (h=f; *h!=y&&*h;) h++; if(*h) { *h = 0; h++; } return h; } (a) It returns a pointer to the first location of y in f. (b) It splits f at the first occurrence of y and then returns a pointer for the remaining string. (c) It finds the last location of y in f, zeros out that location, and then returns a pointer to the next location. (d) It zeros out most of f until it finds y. It then returns a pointer to the location of y in f. (e) Nothing; it cannot be compiled. 3 CS61C Fall 2013 Midterm 9. What does this code print? unsigned char a = 0b01110110; char b = 0b10011010; b >>= 1; b ^= 0b00001101; unsigned char c = a & b; printf("0x%02x",c); (a) 0x40 (b) 0x36 (c) 0x44 (d) 0x01 (e) 0x00 10. What is the FIRST line wrong with this code? Line Code 0 typedef char * yarn; 1 char * get_word() { 2 return "secret"; 3 } 4 void print_word(yarn thread) { 5 printf("%s\n",thread); 6 } 7 int main() { 8 print_word(get_word()); 9 return '\0'; 10 } (a) Line 0: A typedef is being used on a pointer. (b) Line 2: I...
View Full Document

Ask a homework question - tutors are online