Quiz on C++ Pointers
In C++, pointers represent variables that hold the address of other variables. The data type of a pointer is the same as that of a regular variable. Let’s take a quick quiz to see how well we understand Pointers in C++. Happy Learning!
0 of 15 Questions completed Questions: You have already completed the quiz before. Hence you can not start it again. Quiz is loading… You must sign in or sign up to start the quiz. You must first complete the following: 0 of 15 Questions answered correctly Your time: Time has elapsed You have reached 0 of 0 point(s), (0) Earned Point(s): 0 of 0, (0) #include <iostream> using namespace std; int main() { int var = 64, *ptr = &var; char ch = ‘D’; *ptr += ch; cout << var << “, ” << ch << endl; return 0; } #include <iostream> using namespace std; int main() { const int i = 20; const int* const ptr = &i; cout << i<<” “<< *ptr; return 0; } #include <iostream> using namespace std; int main() { const int var = 20; const int* const ptr = &i; *ptr++; cout << i<<” “<< ptr; return 0; } #include <iostream> using namespace std; int main() { int num[5]; int* ptr; ptr = num; *ptr = 10; ptr++; *ptr=*ptr++; ptr++; *ptr=*ptr++; for (int i = 0; i < 5; i++) cout << num[i] << “, “; return 0; } #include <iostream> using namespace std; int main() { int arr[] = { 4, 5, 6, 7 }; int* ptr = (arr + 3); cout << *ptr + 20; return 0; } #include <iostream> using namespace std; int main() { int arr[] = { 4, 5, 6, 7 },*ptr,*ptr1; ptr=&arr[0]; ptr1=arr[1]; cout << “a=” << ptr1; return 0; } #include <iostream> using namespace std; int main() { int arr[5] = { 1, 2, 3, 4, 5 }; for (int i = 0; i < 5; i++) cout << *(arr+4-i) << ” “; return 0; } #include <iostream> using namespace std; void fun(int *arr) { for(int i=0;i<5;i++) { *(arr)=i+*(arr); } } int main() { int arr=6; fun(&arr); cout<<arr<<” “; return 0; } #include <iostream> using namespace std; int fun(int *x) { *x=5; return *x; } int main() { int x = 10, y = 15, i; for (i = 0; i < 1; i++) { int x = 20, y = 25; } int mul = x * y; fun(&mul); cout << *(&mul); return 0; } What is the size of the pointer variable? To allocate an array of integer pointers dynamically, which of the following syntax is correct? On pointers, which operation cannot be performed? Which weakly typed pointer variable is required for explicitly type cast in C++? Quiz Summary
Information
Results
Results
0 Essay(s) Pending (Possible Point(s): 0) Categories
1. Question
2. Question
3. Question
4. Question
5. Question
6. Question
7. Question
8. Question
9. Question
10. Question
11. Question
12. Question
13. Question
14. Question
15. Question
Summary
C++ allows creating pointers to point to pointers that can point to data and other pointers. If you wish to increase the complexity of your understanding of Pointers we suggest learning each concept in detail first. I wish you a great learning experience!
The answer to this question should be C , we do not initialize the contents of the array , and i ran it on Visual Studio to check the output , the first value is initialized by the statement *ptr = 10 , and it replaced the first element of the array from a garbage value to 10 , after that we just increment the array idx and increment the garbage value by one , so C is correct.
how can you add a character in a integer array of pointer