avr39-ripe

pointer QuizZ

Apr 3rd, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. 1. ============================
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a = 32, *ptr = &a;
  8.     char ch = 'A', &cho = ch;
  9.  
  10.     cho += a;
  11.     *ptr += ch;
  12.     cout << a << ", " << ch << endl;
  13.     return 0;
  14. }
  15. Options:
  16. a. 32, A
  17. b. 32, a
  18. c. 129, a
  19. d. 129, A
  20.  
  21. 2.============================
  22. #include <iostream>
  23. using namespace std;
  24.  
  25. int main()
  26. {
  27.     const int i = 20;
  28.     const int* const ptr = &i;
  29.     (*ptr)++;
  30.     int j = 15;
  31.     ptr = &j;
  32.     cout << i;
  33.     return 0;
  34. }
  35. Options:
  36. a. 20
  37. b. 21
  38. c. 15
  39. d. Compile error
  40.  
  41. 3. ============================
  42. #include <iostream>
  43. using namespace std;
  44. int main()
  45. {
  46.     int num[5];
  47.     int* p;
  48.     p = num;
  49.     *p = 10;
  50.     p++;
  51.     *p = 20;
  52.     p = &num[2];
  53.     *p = 30;
  54.     p = num + 3;
  55.     *p = 40;
  56.     p = num;
  57.     *(p + 4) = 50;
  58.     for (int i = 0; i < 5; i++)
  59.         cout << num[i] << ", ";
  60.     return 0;
  61. }
  62. Options:
  63. a. 10, 20, 30, 40, 50
  64. b. 10, 20, 30, 40, 50,
  65. c. compile error
  66. d. runtime error
  67.  
  68. 4. ============================
  69.  
  70. #include <iostream>
  71. using namespace std;
  72. int main()
  73. {
  74.     int arr[] = { 4, 5, 6, 7 };
  75.     int* p = (arr + 1);
  76.     cout << *arr + 10;
  77.     return 0;
  78. }
  79. Options:
  80. a. 12
  81. b. 15
  82. c. 14
  83. d. error
  84.  
  85. 5. ===========================
  86.  
  87. #include <iostream>
  88. using namespace std;
  89. int main()
  90. {
  91.     int a = 10, *pa, &ra;
  92.     pa = &a;
  93.     ra = a;
  94.     cout << "a=" << ra;
  95.     return 0;
  96. }
  97. Options:
  98. a. 10
  99. b. no output
  100. c. compile error
  101. d. runtime error
Advertisement
Add Comment
Please, Sign In to add comment