1 Crore+ students have signed up on EduRev. Have you? Download the App |
What is the return type of a function that doesn't return any value?
What is the output of the following code?
#include <iostream>
using namespace std;
void printNumbers(int n) {
if (n > 0) {
printNumbers(n - 1);
cout << n << " ";
}
}
int main() {
printNumbers(5);
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
void myFunction(int& x) {
x = 10;
}
int main() {
int a = 5;
myFunction(a);
cout << a;
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
int myFunction(int x, int y) {
return x + y;
}
int main() {
int a = 5, b = 3;
cout << myFunction(a, b);
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
int square(int x) {
return x * x;
}
int main() {
cout << square(square(2));
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
int sum(int a, int b) {
return a + b;
}
int sum(int a, int b, int c) {
return a + b + c;
}
int main() {
cout << sum(1, 2) << " ";
cout << sum(1, 2, 3);
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
int factorial(int n) {
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}
int main() {
cout << factorial(5);
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
template <typename T>
T add(T a, T b) {
return a + b;
}
int main() {
cout << add<int>(5, 2) << " ";
cout << add<double>(2.5, 3.7);
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
int main() {
int a = 5;
auto lambda = [&a]() { return a; };
a = 10;
cout << lambda();
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
template <typename T>
void myFunction(T value) {
cout << "Generic" << endl;
}
void myFunction(int value) {
cout << "Integer" << endl;
}
int main() {
myFunction(5);
myFunction(3.14);
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
int main() {
int x = 5;
int& y = x;
y = 10;
cout << x;
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
int main() {
int x = 5;
auto lambda = [x]() mutable { x += 5; return x; };
cout << lambda() << " ";
cout << x;
return 0;
}
What is the purpose of the scope resolution operator (::) in C++?
Which of the following is true about default arguments in C++ functions?
What is the purpose of the "const" keyword in function declarations?
What is the difference between pass-by-value and pass-by-reference in function parameters?
What will be the output of the following code?
#include <iostream>
using namespace std;
void swap(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
int main() {
int x = 5, y = 10;
swap(x, y);
cout << x << " " << y;
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
int myFunction(int x) {
if (x == 0)
return 0;
return x + myFunction(x - 1);
}
int main() {
cout << myFunction(3);
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
void printNumbers(int n) {
if (n <= 0)
return;
cout << n << " ";
printNumbers(n - 1);
}
int main() {
printNumbers(5);
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
int add(int a, int b) {
return a + b;
}
double add(double a, double b) {
return a + b;
}
int main() {
cout << add(5, 2) << " ";
cout << add(2.5, 3.7);
return 0;
}
What will be the output of the following code?
#include <iostream>
using namespace std;
int factorial(int n) {
if (n == 0 || n == 1)
return 1;
return n * factorial(n - 2);
}
int main() {
cout << factorial(5);
return 0;
}
70 videos|45 docs|15 tests
|
70 videos|45 docs|15 tests
|