Which of the following statements is true regarding pointers in C++?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Which of the following statements is true about null pointers in C++?
What is the output of the following code snippet?
int x = 10;
int* ptr = &x;
cout << ptr << endl;
What is the difference between pass-by-value and pass-by-reference in C++?
In C++, what does the 'const' keyword indicate when used with a pointer declaration?
Which of the following statements about array decay in C++ is true?
What is the output of the following code?
int* ptr = new int(5);
cout << *ptr << endl;
delete ptr;
cout << *ptr << endl;
What is the output of the following code?
int arr[] = {1, 2, 3, 4, 5};
int* ptr = arr;
cout << *(ptr + 2) << endl;
What is the output of the following code?
int x = 10;
int* ptr1 = &x;
int** ptr2 = &ptr1;
cout << **ptr2 << endl;
Which of the following is the correct way to declare a function pointer in C++?
What will be the output of the following code snippet?
#include <iostream>
void changeArray(int* arr, int size) {
for (int i = 0; i < size; i++) {
arr[i] *= 2;
}
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
changeArray(arr, 5);
for (int i = 0; i < 5; i++) {
std::cout << arr[i] << " ";
}
return 0;
}
What is the output of the following code snippet?
#include <iostream>
void printValues(int* ptr) {
for (int i = 0; i < 5; i++) {
std::cout << *ptr << " ";
ptr++;
}
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
printValues(arr);
return 0;
}
What will be the output of the following code snippet?
#include <iostream>
void changeValue(int* ptr) {
*ptr = 10;
}
int main() {
int x = 5;
int* ptr = &x;
changeValue(ptr);
std::cout << x;
return 0;
}
What does the following code snippet do?
int* createArray(int size) {
int* arr = new int[size];
return arr;
}
Consider the following code snippet:
#include <iostream>
void printArray(int arr[]) {
std::cout << arr[0];
}
int main() {
int arr[5] = {1, 2, 3, 4, 5};
printArray(arr);
return 0;
}
What will be the output of the above code?
Consider the following code snippet:
#include <iostream>
void incrementValue(int& num) {
num++;
}
int main() {
int x = 5;
incrementValue(x);
std::cout << x;
return 0;
}
What will be the output of the above code?
Consider the following code snippet:
#include <iostream>
void changeArraySize(int** arr, int size) {
*arr = new int[size];
}
int main() {
int* arr = nullptr;
changeArraySize(&arr, 5);
std::cout << (arr != nullptr);
delete[] arr;
return 0;
}
What will be the output of the above code?
Consider the following code snippet:
#include <iostream>
int main() {
int* ptr = nullptr;
std::cout << (ptr == nullptr);
return 0;
}
What will be the output of the above code?
Consider the following code snippet:
#include <iostream>
void changeValue(int* ptr) {
*ptr = 20;
ptr = nullptr;
}
int main() {
int x = 10;
int* ptr = &x;
changeValue(ptr);
std::cout << (ptr == nullptr);
return 0;
}
What will be the output of the above code?
Consider the following code snippet:
#include <iostream>
void printValues(int* ptr, int size) {
for (int i = 0; i < size; i++) {
std::cout << *ptr << " ";
ptr++;
}
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
printValues(arr + 2, 3);
return 0;
}
What will be the output of the above code?v
Consider the following code snippet:
#include <iostream>
void swapValues(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
int main() {
int x = 5;
int y = 10;
swapValues(x, y);
std::cout << x << " " << y;
return 0;
}
What will be the output of the above code?
Consider the following code snippet:
#include <iostream>
int* createArray(int size) {
int arr[size];
return arr;
}
int main() {
int* ptr = createArray(5);
std::cout << (ptr != nullptr);
return 0;
}
What will be the output of the above code?
Consider the following code snippet:
#include <iostream>
int main() {
int* ptr = new int;
*ptr = 10;
std::cout << *ptr;
delete ptr;
return 0;
}
What will be the output of the above code?
Consider the following code snippet:
#include <iostream>
void processValues(int* ptr, int size) {
for (int i = 0; i < size; i++) {
std::cout << *ptr << " ";
ptr++;
}
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
processValues(arr + 1, 3);
return 0;
}
What will be the output of the above code?