Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. 1. Suppose you have the following Program.
  2. //No includes
  3. int main()
  4. {
  5. printf("Hello World!!!\n");
  6. //No returns
  7. }
  8.  
  9. Will this code compile and run successfully?
  10. ===============================================================
  11. 2. Let us suppose a program executes the following instructions:
  12.  
  13. for (i = 0; i < n; i++) fork();
  14.  
  15. How many processes are created in total (in terms of n)?
  16. ===============================================================
  17. 3. Say we run this program.
  18.  
  19. if (fork() == 0)
  20. { a = a + 5; printf(“x = %d,y = %d\n”, a, &a); }
  21. else { a = a –5; printf(“u = %d, v = %d\n”, a, &a); }
  22. ===============================================================
  23. Which of the following are true ?
  24. (a) u = x + 10 and v = y
  25. (b) u = x + 10 and v != y
  26. (c) u + 10 = x and v = y
  27. (d) u + 10 = x and v != y
  28. ===============================================================
  29. 4. What is the output of this program ?
  30. int main () {
  31. int i, j, *p, *q;
  32. p = &i;
  33. q = &j;
  34. *p = 5;
  35. *q = *p + i;
  36. printf("i = %d, j = %d\n", i, j);
  37. return 0;
  38. }
  39. a) i = 5, j = 10
  40. b) i = 5, j = 5
  41. c) i = 10, j = 5
  42. d) i = 10, j = 10
  43. e) Nothing. The program will most likely crash.
  44. ================================================================
  45. 5. Where does the "hello world" reside ?
  46. int main() {
  47. const char *str = "hello world";
  48. printf("%s\n", str);
  49. }
  50. a) .text section b) .data section c) .bss section d) stack e) heap
  51. ================================================================
  52. 6. What does the following command give you on a 64 bit machine with a 32 bit compiler?
  53. {
  54. printf("char=%d, int=%d, long=%d", sizeof(char), sizeof(int), sizeof(long));
  55. }
  56. a) char=4, int=4, long=4
  57. b) char=1, int=4, long=4
  58. c) char=1, int=4, long=8
  59. d) char=1, int=8, long=8
  60. e) compilation error
  61.  
  62. 7. Suppose you compile a code and send the binary to your friends computer (Both your computers have different configuration etc).
  63. Will it run ? When will it not run?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement