1) Figure out what the expression and/or statements evaluate to or print. 2) Short answer or fill-in the blank about C. Note - they're a bit mixed up in this file ... 1a) char c[10] = "jklmno"; for(int i=0; i<26; i++){ c[i] += 2; } printf("%s\n", c); answer: * run-time error because c[25] is not okay. * "lmnopq"... 2a) What is the difference between a signed integer and unsigned integer? Specifically, what is the difference between int x; // range is -2^31 to 2^31 - 1 unsigned int y; // range 0 to 2^32 - 1 answer: 1b) int i = 64; i = i << 1; 128, 1000 0000b i = i | 0x12; 0001 0010b -> 1001 0010 i = i >> 3; 1 0010b printf("%i\n", i); 18 Answer: 2b) What keyword identifies a loop that keeps track of a variable for you? Answer: for ** Note - this question is both too vague and too easy. 1c) int num = 123456; int i; for(i=0;i<3;i++) num1 = num1 + (1 << i); // 123456 + 1 = 123457 + 2 = 1234569 + 4 = 1234573 printf("%d",num1); what is the value of num1? answer: 2c) (True/False) A variable of an enumerated (enum) type only takes one value? Answer: True ** Note: question is vague and could be misunderstood. 1d) int a = 0x00; a |= 0xab; a &= 0x0f; // 0x0000 000b a = ~a; // 0xffff fff4 a >> 2; // 0x3fff fffd printf("%d %x\n", a, a); 2d) What is struct used for? Struct is used for collecting variables that are related to create a new type. ** Note - too vague, it is better to ask something specific where it is easy to determine if you are correct or not. 1e) int main() int x=50; x = x % 3 + 5; // 2+5 = 7 x = x>>1; // 3 printf("%d\n", x); Answer: 2e) How many bytes does a long double take in memory when using gcc on CS? Answer: (use sizeof) sizeof(long double) 16 1f) int i; char c[10] = "abcdef"; bbddff for (i = 0; c[i]; i++) c[i] += c[i] & 0x1; // c[0] += 1 // c[1] += 98 + 0x1 printf("%s\n", c); Answer: 1g) int i; char c[100] = "HeLLoWoRLD"; for (i = 0; c[i]; i++) // if (c[i] & 32) "false"; else "true"; printf("c[%d] '%c' -> %s\n", i, c[i], (c[i] & 32) ? "false":"true"); c[0], 'H' -> true c[1], 'e' -> false 97+_ & 32 0110 0001 65+_ & 32 0100 0001 0010 0000 Answer: 1h). char c = 'a'; // 97 c += 4 + ('X'-'W'); //102 c -= 2*2-1;//102-(4-1) = 98 c -= ('a'-'A'); 98 - (97-65) = 66 printf("%c\n", c); // B printf("%d\n", c); // 66 answer: 2f. What happens when you use return in a function? Answer: The function is terminated and the value is returned. ** Note - too easy? 1i) int num = 70 % 8 * 2 + 4 % 3; 4 * 2 + 4 % 3 8 + 4 % 3 8 + 1 9 2g) What is the storage size and value range of an unsigned char on CS with gcc? ** Note - very nice, specific enough to easily tell if someone knows this or not based on their answer 1 byte, 0 to 255 1j) int main(int argc, char *argv[]){ char c = 'c'; // 99 c += c>>2; 99 + 99/4 = 99 + 24 = 123 for(int i=1; i<4;i++) c = ++c | i; 124 | 1 = 125 126 | 2 = 126 127 | 3 = 127 // 0111 1111 // 11 printf("%i\n", c); //prints 127 } 2h) What does the variable argc contain? Answer: the number of command lines arguments 1k) #include #include int main(int argc,char *argv[]){ float number=10; for(int i=0; i<=number; i++){ printf("%.0lf x %d = %.0lf\n", number, i, i*number); 10 x 0 = 0 10 x 1 = 10 ... 10 x 10 = 100 } printf("------------------\n"); for (int k=1; k<=number; k++){ printf("%.0lf / %d = %.2lf\n", number, k, number/k); 10 / 1 = 10.00 10 / 2 = 5.00 10 / 3 = 3.33 10 / 4 = 2.50 ... } return 0; } 2i) What is a SWITCH statement in C? Answer: ** Note -- too vague