Which of the following is the correct way to declare a pointer variable in C++?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
What is the output of the following code snippet?
int x = 5;
int* ptr = &x;
cout << *ptr;
Which operator is used to access the value pointed to by a pointer in C++?
What is the output of the following code snippet?
int arr[] = {1, 2, 3, 4, 5};
int* ptr = arr;
cout << *(ptr + 2);
Which of the following is true about pointer arithmetic in C++?
What is the purpose of the 'const' keyword when used with a pointer in C++?
What is the output of the following code snippet?
int x = 5;
int* ptr = &x;
*ptr = 10;
cout << x;
What is the output of the following code snippet?
int arr[] = {1, 2, 3, 4, 5};
int* ptr = arr;
cout << *ptr++;
What is the output of the following code snippet?
int arr[] = {1, 2, 3, 4, 5};
int* ptr = arr + 2;
cout << *ptr;
What is the output of the following code snippet?
int arr[] = {1, 2, 3, 4, 5};
int* ptr = arr;
cout << *(ptr + 3);
What is the output of the following code snippet?
int arr[] = {1, 2, 3, 4, 5};
int* ptr = arr;
cout << ptr[2];
What is the output of the following code snippet?
int x = 5;
int* ptr1 = &x;
int* ptr2 = ptr1;
*ptr2 = 10;
cout << *ptr1;
What is the output of the following code snippet?
int x = 5;
int* ptr = &x;
int** ptr2 = &ptr;
cout << **ptr2;
What is the output of the following code snippet?
int x = 5;
int* ptr1 = &x;
int* ptr2 = nullptr;
ptr2 = ptr1;
*ptr2 = 10;
cout << *ptr1;
What is the output of the following code snippet?
int arr[] = {1, 2, 3, 4, 5};
int* ptr1 = arr;
int* ptr2 = ptr1 + 3;
cout << ptr2 - ptr1;
What is the output of the following code snippet?
int arr[] = {1, 2, 3, 4, 5};
int* ptr = arr + 4;
cout << *(ptr - 2);
What is the output of the following code snippet?
int* ptr = new int[5];
ptr[2] = 10;
cout << ptr[2];
delete[] ptr;
What is the output of the following code snippet?
int** ptr = new int*[3];
for (int i = 0; i < 3; i++) {
ptr[i] = new int[2];
for (int j = 0; j < 2; j++) {
ptr[i][j] = i + j;
}
}
cout << ptr[2][1];
for (int i = 0; i < 3; i++) {
delete[] ptr[i];
}
delete[] ptr;
What is the output of the following code snippet?
void print(int* arr, int size) {
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
int* ptr = arr;
print(ptr, 5);
return 0;
}
What is the output of the following code snippet?
#include <memory>
int main() {
std::unique_ptr<int> ptr(new int(5));
std::cout << *ptr;
return 0;
}
70 videos|45 docs|15 tests
|
70 videos|45 docs|15 tests
|