Which operator is used to dynamically allocate memory in C++?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
What does the keyword "inline" indicate in a function declaration?
Which keyword is used to declare a constant variable in C++?
What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
int* ptr = new int(5);
cout << *ptr << endl;
delete ptr;
return 0;
}
What is the output of the following code?
#include <iostream>
using namespace std;
#define SQUARE(x) x*x
int main() {
int num = 5;
cout << SQUARE(num + 1) << endl;
return 0;
}
What is the output of the following code?
#include <iostream>
using namespace std;
int sum(int x = 2, int y = 3);
int main() {
cout << sum(5) << endl;
return 0;
}
int sum(int x, int y) {
return x + y;
}
What is the output of the following code?
#include <iostream>
using namespace std;
static int count = 0;
int main() {
cout << count++ << endl;
count++;
cout << count << endl;
return 0;
}
What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
const int x = 5;
int* ptr = (int*)&x;
*ptr = 10;
cout << x << endl;
return 0;
}
What is the output of the following code?
```cpp
#include <iostream>
using namespace std;
inline int multiply(int a, int b) {
return a * b;
}
int main() {
int result = multiply(2, 3) + multiply(4, 5);
cout << result << endl;
return 0;
}
```
What is the output of the following code?
```cpp
#include <iostream>
using namespace std;
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int main() {
int num1 = 10, num2 = 5, num3 = 8;
int maxNum = MAX(num1++, num2++);
cout << maxNum << endl;
return 0;
}
```
What is the output of the following code?
```cpp
#include <iostream>
using namespace std;
const int num = 5;
void increment() {
const int num = 10;
cout << ++num << endl;
}
int main() {
increment();
cout << num << endl;
return 0;
}
```
What is the output of the following code?
```cpp
#include <iostream>
using namespace std;
int getValue() {
static int num = 0;
num++;
return num;
}
int main() {
cout << getValue() << endl;
cout << getValue() << endl;
cout << getValue() << endl;
return 0;
}
```
What is the output of the following code?
```cpp
#include <iostream>
using namespace std;
int main() {
const int arr[] = {1, 2, 3};
int* ptr = const_cast<int*>(arr);
*ptr = 10;
cout << arr[0] << endl;
return 0;
}
```