|
4 | 4 |
|
5 | 5 |
|
6 | 6 |
|
| 7 | + ------------------------------------------------------------------------ |
| 8 | + /*/*/*/*/* F.I.N.A.L E.X.A.M */*/*/*/*/ |
| 9 | + ------------------------------------------------------------------------ |
| 10 | + ------------------------------------------------------------------------ |
| 11 | + |
| 12 | + |
| 13 | + |
7 | 14 | --------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 15 | +1. Who invented the C language? |
| 16 | + |
| 17 | +Ans. Dennis Ritchie invented C at Bell Labs |
| 18 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 19 | + |
| 20 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 21 | +2. When you compile a correct C program you get a machine executable file such as a.out produced by the gnu compiler gcc. |
| 22 | + |
| 23 | +Ans. True |
| 24 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 25 | + |
| 26 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 27 | +3. Which is true: |
| 28 | + |
| 29 | + 1 - #define is a preprocessor command often used to introduce named constants |
| 30 | + 2 - double and goto are keywords declaring types. |
| 31 | + 3 - return (0); is normally the last statement in main() |
| 32 | + 4 - The file stdio.h is where the compiler finds scanf(). |
| 33 | + |
| 34 | +Ans. 1, 3, 4 |
| 35 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 36 | + |
| 37 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 38 | +4. The statement -- printf(“HELLO\t\tWORLD\n”); |
| 39 | + |
| 40 | +Ans. Prints HELLO WORLD followed by a new line |
| 41 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 42 | + |
| 43 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 44 | +5. The expression PI * radius * radius would be used to compute |
| 45 | + |
| 46 | +Ans. A circle's area |
| 47 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 48 | + |
| 49 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 50 | +6. In a format string for printf which would you use to print an int? |
| 51 | + |
| 52 | +Ans. %d |
| 53 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 54 | + |
| 55 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 56 | +7. The code |
| 57 | + |
| 58 | +>> |
| 59 | +i = -10; |
| 60 | +while ( i < 0) |
| 61 | +{ … do something ; i--; } |
| 62 | +**--Displays a common error--** |
| 63 | + |
| 64 | + |
| 65 | +Ans. Its an infinite loop |
| 66 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 67 | + |
| 68 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 69 | +8. The following program is suppose to write Hello World onto the screen but it has syntax errors - find |
| 70 | +and correct. |
| 71 | + |
| 72 | +>> |
| 73 | +#include <stdio.h> |
| 74 | +int main(void) |
| 75 | +{ |
| 76 | + printf(“ Hello World\n”); |
| 77 | + return 0, |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +Ans. It should be return 0; |
| 82 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 83 | + |
| 84 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 85 | +9. Assume the given declarations and fill in the value of the expression . |
| 86 | +int a = 3, b = 4, c = 0, d = '1'; |
| 87 | + |
| 88 | +Expression: a % b |
| 89 | + |
| 90 | +Ans. Enter answer here -- 3 |
| 91 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 92 | + |
| 93 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 94 | +10. Assume the given declarations and fill in the value of the expression . |
| 95 | +int a = 3, b = 4, c = 0, d = '1'; |
| 96 | + |
| 97 | +Expression: b % a |
| 98 | + |
| 99 | +Ans. Enter answer here -- 1 |
| 100 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 101 | + |
| 102 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 103 | +11. Assume the given declarations and fill in the value of the expression . |
| 104 | +int a = 3, b = 4, c = 0, d = '1'; |
| 105 | + |
| 106 | +Expression: a < b |
| 107 | + |
| 108 | +Ans. Enter answer here -- 1 |
| 109 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 110 | + |
| 111 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 112 | +12. Assume the given declarations and fill in the value of the expression . |
| 113 | +int a = 3, b = 4, c = 0, d = '1'; |
| 114 | + |
| 115 | +Expression: c < b && a > 3 |
| 116 | + |
| 117 | +Ans. Enter answer here -- 0 |
| 118 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 119 | + |
| 120 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 121 | +13. Assume the given declarations and fill in the value of the expression . |
| 122 | +int a = 3, b = 4, c = 0, d = '1'; |
| 123 | + |
| 124 | +Expression: a / b > c |
| 125 | + |
| 126 | +Ans. Enter answer here -- 0 |
| 127 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 128 | + |
| 129 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 130 | +14. Assume the given declarations and fill in the value of the expression . |
| 131 | +int a = 3, b = 4, c = 0, d = '1'; |
| 132 | + |
| 133 | +Expression: c = a++ |
| 134 | + |
| 135 | +Ans. Enter answer here -- 3 |
| 136 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 137 | + |
| 138 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 139 | +15. Assume the given declarations and fill in the value of the expression . |
| 140 | +int a = 1, b = 2, c = 3; |
| 141 | + |
| 142 | +Expression: a - b * c |
| 143 | + |
| 144 | +Ans. Enter answer here -- (-5) |
| 145 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 146 | + |
| 147 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 148 | +16. Assume the given declarations and fill in the value of the expression . |
| 149 | +int a = 1, b = 2, c = 3; |
| 150 | + |
| 151 | +Expression: c / a * b |
| 152 | + |
| 153 | +Ans. Enter answer here -- 6 |
| 154 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 155 | + |
| 156 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 157 | +17. Assume the given declarations and fill in the value of the expression . |
| 158 | +int a = 1, b = 2, c = 3; |
| 159 | + |
| 160 | +Expression: a++ + --b |
| 161 | + |
| 162 | +Ans. Enter answer here -- 2 |
| 163 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 164 | + |
| 165 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 166 | +18. Assume the given declarations and fill in the value of the expression . |
| 167 | +int a = 1, b = 2, c = 3; |
| 168 | + |
| 169 | +Expression: b = a = c |
| 170 | + |
| 171 | +Ans. Enter answer here -- 3 |
| 172 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 173 | + |
| 174 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 175 | +19. Assume the given declarations and fill in the value of the expression . |
| 176 | +int i = 0, j = 1, k = 2; |
| 177 | + |
| 178 | +Expression: i && j |
| 179 | + |
| 180 | +Ans. Enter answer here -- 0 |
| 181 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 182 | + |
| 183 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 184 | +20. Assume the given declarations and fill in the value of the expression . |
| 185 | +int i = 0, j = 1, k = 2; |
| 186 | + |
| 187 | +Expression: !!i |
| 188 | + |
| 189 | +Ans. Enter answer here -- 0 |
| 190 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 191 | + |
| 192 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 193 | +21. Assume the given declarations and fill in the value of the expression . |
| 194 | +int i = 0, j = 1, k = 2; |
| 195 | + |
| 196 | +Expression: i || !k |
| 197 | + |
| 198 | +Ans. Enter answer here 0 |
| 199 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 200 | + |
| 201 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 202 | +22. Assume the given declarations and fill in the value of the expression. |
| 203 | +int i = 0, j = 1, k = 2; |
| 204 | + |
| 205 | +Expression: (i && (j = k)) || (k > j) |
| 206 | + |
| 207 | +Ans. Enter answer here -- 1 |
| 208 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 209 | + |
| 210 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 211 | +23. If a function’s declaration is int foo(void): |
| 212 | + |
| 213 | +Ans. The function has no arguments |
| 214 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 215 | + |
| 216 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 217 | +24. In ANSI standard C(1989) code - this is what we are teaching- declarations can occur in a for statement as in : |
| 218 | + |
| 219 | +>> |
| 220 | +for(int i; i < 10; i++0 … |
| 221 | + |
| 222 | + |
| 223 | +Ans. False |
| 224 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 225 | + |
| 226 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 227 | +25. What happens when the return statement has a double expression and the function return type is int? |
| 228 | + |
| 229 | +Ans. There is a conversion from double to int |
| 230 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 231 | + |
| 232 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 233 | +26. With the code : |
| 234 | + |
| 235 | +>> |
| 236 | +int foobar(int* n){ |
| 237 | + *n = *n +1; |
| 238 | + return *n; |
| 239 | +} |
| 240 | + |
| 241 | + when called: |
| 242 | + |
| 243 | +>> |
| 244 | +int k = 6; |
| 245 | +printf("foobar(k) = %d,",foobar(&k) ); |
| 246 | +printf(" k = %d\n", k); |
| 247 | +what gets printed? |
| 248 | + |
| 249 | + |
| 250 | +Ans. foobar(k) = 7, k = 7 |
| 251 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 252 | + |
| 253 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 254 | +27. A variable declared in a inner block that has the same name as one in the surrounding block causes an error. |
| 255 | + |
| 256 | +Ans. False |
| 257 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 258 | + |
| 259 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 260 | +28. The original intent of using register int i; |
| 261 | + |
| 262 | +Ans. It was intended to compile optimized code |
| 263 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 264 | + |
| 265 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 266 | +29. When declaring fact() why not use double fact() so that you do not have integer overflow? |
| 267 | + |
| 268 | +Ans. There would be problems with accuracy |
| 269 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 270 | + |
| 271 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 272 | +30. Factorial can only be computed recursively. |
| 273 | + |
| 274 | +Ans. False |
| 275 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 276 | + |
| 277 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 278 | +31. The function mystery is defined as |
| 279 | + |
| 280 | + |
| 281 | +>> |
| 282 | +int mystery(int p, int q) |
| 283 | +{ |
| 284 | + int r; |
| 285 | + if ((r = p % q) == 0) |
| 286 | + return q; |
| 287 | + else return mystery(q, r); |
| 288 | +} |
| 289 | + |
| 290 | +When called with mystery(2, 6) it will return: |
| 291 | + |
| 292 | + |
| 293 | +Ans. 2 |
| 294 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 295 | + |
| 296 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 297 | +32. The function mystery is defined as |
| 298 | + |
| 299 | +>> |
| 300 | +int mystery(int p, int q) |
| 301 | +{ |
| 302 | + int r; |
| 303 | + if ((r = p % q) == 0) |
| 304 | + return q; |
| 305 | + else return mystery(q, r); |
| 306 | +} |
| 307 | + |
| 308 | +When called with mystery(7, 91) it will return: |
| 309 | + |
| 310 | + |
| 311 | +Ans. 7 |
| 312 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 313 | + |
| 314 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 315 | +33. A while can always be used to replace a for. |
| 316 | + |
| 317 | +Ans. True |
| 318 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 319 | + |
| 320 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 321 | +34. An if-else statement can always replace an if statement. |
| 322 | + |
| 323 | +Ans. True |
| 324 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 325 | + |
| 326 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 327 | +35. If you declare the array char mystr[10]; |
| 328 | + |
| 329 | +Ans. None of these |
| 330 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 331 | + |
| 332 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 333 | +36. In the following code fragment what gets printed? |
| 334 | + |
| 335 | +>> |
| 336 | +int data[5] = {0 ,1, 2, 3, 4}, sum = 0 , i; |
| 337 | + |
| 338 | +for (i = 0; i < 5 ; i++) |
| 339 | + sum = sum + data[i]; |
| 340 | +printf(“%d\n”, sum); |
| 341 | + |
| 342 | + |
| 343 | +Ans. 10 |
| 344 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 345 | + |
| 346 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 347 | +37. In the following code fragment |
| 348 | + |
| 349 | +>> |
| 350 | +int a[10] = {1,2,3,4,5,6,7,8,9,10}, i = 6 ; |
| 351 | +int *p = &a[0]; |
| 352 | +printf(“%d\n”, *(p + i)); |
| 353 | + |
| 354 | +what gets printed? |
| 355 | + |
| 356 | + |
| 357 | +Ans. 7 |
| 358 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 359 | + |
| 360 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 361 | +38. The declaration char* str = & a[0]; where char a[5] = “abcd”; |
| 362 | +The value of *str is the char ‘a’; |
| 363 | + |
| 364 | +Ans. True |
| 365 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 366 | + |
| 367 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 368 | +39. The input function scanf() uses “call by reference” to pass in argument values. |
| 369 | + |
| 370 | +Ans. True |
| 371 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 372 | + |
| 373 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 374 | +40. Mergesort is less efficient than bubblesort for very large sorting problems. |
| 375 | + |
| 376 | +Ans. False |
| 377 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 378 | + |
| 379 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 380 | +41. if p and q are pointers to double and x and y are double which of the following is legal: |
| 381 | + |
| 382 | +Ans. y = *q; |
| 383 | +-------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 384 | + |
| 385 | + |
| 386 | + |
| 387 | +~ TSG405, 2021 |
0 commit comments