EmSAT Achieve Exam  >  EmSAT Achieve Tests  >  C++ for EmSAT Achieve  >  Test: Functions - 1 - EmSAT Achieve MCQ

Test: Functions - 1 - EmSAT Achieve MCQ


Test Description

30 Questions MCQ Test C++ for EmSAT Achieve - Test: Functions - 1

Test: Functions - 1 for EmSAT Achieve 2024 is part of C++ for EmSAT Achieve preparation. The Test: Functions - 1 questions and answers have been prepared according to the EmSAT Achieve exam syllabus.The Test: Functions - 1 MCQs are made for EmSAT Achieve 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Functions - 1 below.
Solutions of Test: Functions - 1 questions in English are available as part of our C++ for EmSAT Achieve for EmSAT Achieve & Test: Functions - 1 solutions in Hindi for C++ for EmSAT Achieve course. Download more important topics, notes, lectures and mock test series for EmSAT Achieve Exam by signing up for free. Attempt Test: Functions - 1 | 30 questions in 60 minutes | Mock test for EmSAT Achieve preparation | Free important questions MCQ to study C++ for EmSAT Achieve for EmSAT Achieve Exam | Download free PDF with solutions
Test: Functions - 1 - Question 1

Which of the following best describes a function in C++?

Detailed Solution for Test: Functions - 1 - Question 1

Functions in C++ are used to group a set of instructions together to perform a specific task. They allow code reuse and modularization.

Test: Functions - 1 - Question 2

What is a function parameter in C++?

Detailed Solution for Test: Functions - 1 - Question 2

A function parameter in C++ is an input value passed to a function. It allows the function to accept different values for processing.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Functions - 1 - Question 3

In C++, which keyword is used to indicate the end of a function's execution and return a value?

Detailed Solution for Test: Functions - 1 - Question 3

The return keyword is used in C++ to indicate the end of a function's execution and to return a value back to the caller.

Test: Functions - 1 - Question 4

What is function overloading in C++?

Detailed Solution for Test: Functions - 1 - Question 4

Function overloading in C++ involves writing multiple functions with the same name but different parameter types. This allows the same function name to be used for different variations of the function's behavior.

Test: Functions - 1 - Question 5

Which of the following statements is true regarding function overloading in C++?

Detailed Solution for Test: Functions - 1 - Question 5

Overloaded functions can have different parameter types, but they must have a different number of parameters or parameters of different types to be distinguishable.

Test: Functions - 1 - Question 6

How is a function called in C++?

Detailed Solution for Test: Functions - 1 - Question 6

A function is called in C++ by writing its name followed by parentheses. Arguments can be passed inside the parentheses if the function expects any.

Test: Functions - 1 - Question 7

Which of the following is not a valid function declaration in C++?

Detailed Solution for Test: Functions - 1 - Question 7

This is not a valid function declaration in C++. Function definitions should have a body enclosed in curly braces. The correct declaration should be: int myFunction(int a, int b);

Test: Functions - 1 - Question 8

What is the purpose of a function prototype in C++?

Detailed Solution for Test: Functions - 1 - Question 8

A function prototype in C++ is used to declare the existence of a function, specifying its name, return type, and parameter types. It provides information about the function before its actual definition.

Test: Functions - 1 - Question 9

Which of the following is an example of a recursive function?

Detailed Solution for Test: Functions - 1 - Question 9

A recursive function is a function that calls itself during its execution. This can be useful for solving problems that can be broken down into smaller subproblems.

Test: Functions - 1 - Question 10

What is the scope of a variable declared inside a function in C++?

Detailed Solution for Test: Functions - 1 - Question 10

A variable declared inside a function in C++ has local scope, which means it is only accessible within that function. It cannot be accessed from outside the function.

Test: Functions - 1 - Question 11

What will be the output of the following code?

#include <iostream>

int myFunction(int x, int y) {
    return x + y;
}

int main() {
    int result = myFunction(5, 3);
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 11

The code defines a function myFunction that takes two integers and returns their sum. In main, the function is called with arguments 5 and 3, and the result is assigned to result. The value of result is then printed, which is 8.

Test: Functions - 1 - Question 12

What will be the output of the following code?

#include <iostream>

void myFunction(int x) {
    std::cout << "Value: " << x << std::endl;
}

int main() {
    int value = 10;
    myFunction(value);
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 12

The code defines a function myFunction that takes an integer x and prints its value. In main, an integer variable value is declared and assigned a value of 10. The function myFunction is then called with value as an argument, resulting in the output "Value: 10".

Test: Functions - 1 - Question 13

What will be the output of the following code?

#include <iostream>

int add(int x, int y) {
    return x + y;
}

int multiply(int x, int y) {
    return x * y;
}

int main() {
    int result = add(2, multiply(3, 4));
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 13

The code defines two functions: add and multiply, both taking two integers as parameters. In main, the function add is called with arguments 2 and the result of multiply(3, 4) (which is 12). The returned value, 14, is then printed.

Test: Functions - 1 - Question 14

What will be the output of the following code?

#include <iostream>

int myFunction(int& x) {
    x += 5;
    return x;
}

int main() {
    int value = 10;
    int result = myFunction(value);
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 14

The code defines a function myFunction that takes an integer reference x and increments its value by 5. In main, an integer variable value is declared and assigned a value of 10. The function myFunction is called with value as an argument, modifying its value to 15. The modified value is then assigned to result and printed, resulting in the output "15".

Test: Functions - 1 - Question 15

What will be the output of the following code?

#include <iostream>

int add(int x, int y) {
    return x + y;
}

int add(int x, int y, int z) {
    return x + y + z;
}

int main() {
    int result = add(2, 3);
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 15

The code defines two functions named add. The first add function takes two integers as parameters and returns their sum. The second add function takes three integers as parameters and returns their sum. In main, the first add function is called with arguments 2 and 3, resulting in a sum of 5. The value of 5 is then printed.

Test: Functions - 1 - Question 16

What will be the output of the following code?

#include <iostream>

int myFunction(int x) {
    return x * 2;
}

int myFunction(int x, int y) {
    return x + y;
}

int main() {
    int result1 = myFunction(2);
    int result2 = myFunction(2, 3);
    std::cout << result1 << " " << result2 << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 16

The code defines two functions named myFunction. The first myFunction takes an integer x and returns its doubled value. The second myFunction takes two integers x and y and returns their sum. In main, the first myFunction is called with an argument of 2, resulting in a value of 4. The second myFunction is called with arguments 2 and 3, resulting in a value of 5. The values 4 and 5 are then printed.

Test: Functions - 1 - Question 17

What will be the output of the following code?

#include <iostream>

void myFunction(int x) {
    if (x <= 0)
        return;
    
    std::cout << x << std::endl;
    myFunction(x - 1);
}

int main() {
    myFunction(5);
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 17

The code defines a function myFunction that takes an integer x. Inside the function, it checks if x is less than or equal to 0 and returns if true. Otherwise, it prints the value of x and calls itself recursively with x decremented by 1. In main, myFunction is called with an argument of 5. During the recursive calls, the values 5, 4, 3, 2, and 1 are printed.

Test: Functions - 1 - Question 18

What will be the output of the following code?

#include <iostream>

int myFunction(int x) {
    if (x <= 1)
        return x;
    
    return myFunction(x - 1) + x;
}

int main() {
    int result = myFunction(4);
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 18

The code defines a function myFunction that takes an integer x. Inside the function, it checks if x is less than or equal to 1 and returns x if true. Otherwise, it calls itself recursively with x decremented by 1 and adds x to the result. In main, myFunction is called with an argument of 4. The recursive calls result in the calculation 4 + 3 + 2 + 1, which equals 10. The value 10 is then printed.

Test: Functions - 1 - Question 19

What will be the output of the following code?

#include <iostream>

int myFunction(int x) {
    if (x <= 1)
        return x;
    
    return myFunction(x - 1) * x;
}

int main() {
    int result = myFunction(4);
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 19

The code defines a function myFunction that takes an integer x. Inside the function, it checks if x is less than or equal to 1 and returns x if true. Otherwise, it calls itself recursively with x decremented by 1 and multiplies the result by x. In main, myFunction is called with an argument of 4. The recursive calls result in the calculation 4 * 3 * 2 * 1, which equals 24. The value 24 is then printed.

Test: Functions - 1 - Question 20

What will be the output of the following code?

#include <iostream>

void myFunction(int x) {
    std::cout << "Value: " << x << std::endl;
}

int main() {
    int value = 10;
    myFunction(value++);
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 20

The code defines a function myFunction that takes an integer x and prints its value. In main, an integer variable value is declared and assigned a value of 10. The myFunction is then called with value++ as an argument. The value of value++ is temporarily stored as 10, and the myFunction is called with that value. The value 10 is printed inside the function. After the function call, the value of value is incremented to 11. Finally, the incremented value of value is printed outside the function, resulting in the output "Value: 12".

Test: Functions - 1 - Question 21

What will be the output of the following code?

#include <iostream>

int myFunction(int x) {
    return x * x;
}

int myFunction(int& x) {
    return ++x;
}

int main() {
    int value = 5;
    int result = myFunction(value);
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 21

The code defines two overloaded functions named myFunction. The first myFunction takes an integer x and returns its square. The second myFunction takes an integer reference x and increments its value. In main, an integer variable value is declared and assigned a value of 5. The first myFunction is called with value as an argument, resulting in a return value of 25. The value 25 is then printed.

Test: Functions - 1 - Question 22

What will be the output of the following code?

#include <iostream>

int myFunction(int x, int y) {
    return x - y;
}

int main() {
    int result = myFunction(5, 3) * 2;
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 22

The code defines a function myFunction that takes two integers x and y and returns their difference. In main, the function myFunction is called with arguments 5 and 3, resulting in a difference of 2. The difference is then multiplied by 2, resulting in the output of 8.

Test: Functions - 1 - Question 23

What will be the output of the following code?

#include <iostream>

void myFunction(int x) {
    std::cout << "Value: " << x << std::endl;
}

void myFunction(int* x) {
    std::cout << "Pointer: " << *x << std::endl;
}

int main() {
    int value = 10;
    myFunction(&value);
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 23

The code defines two overloaded functions named myFunction. The first myFunction takes an integer x and prints its value. The second myFunction takes an integer pointer x and prints the value pointed to by x. In main, an integer variable value is declared and assigned a value of 10. The address of value is passed to the second myFunction, resulting in the output "Pointer: 10".

Test: Functions - 1 - Question 24

What will be the output of the following code?

#include <iostream>

int myFunction(int x) {
    if (x == 0)
        return 0;
    
    return x + myFunction(x - 1);
}

int main() {
    int result = myFunction(4);
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 24

The code defines a recursive function myFunction that takes an integer x. Inside the function, it checks if x is equal to 0 and returns 0 if true. Otherwise, it adds x to the result of the recursive call with x decremented by 1. In main, myFunction is called with an argument of 4. The recursive calls result in the calculation 4 + 3 + 2 + 1 + 0, which equals 10. The value 10 is then printed.

Test: Functions - 1 - Question 25

What will be the output of the following code?

#include <iostream>

void myFunction(int x) {
    if (x <= 0)
        return;
    
    myFunction(x - 1);
    std::cout << x << " ";
}

int main() {
    myFunction(5);
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 25

The code defines a recursive function myFunction that takes an integer x. Inside the function, it checks if x is less than or equal to 0 and returns if true. Otherwise, it calls itself recursively with x decremented by 1 and prints x before the recursive call. In main, myFunction is called with an argument of 5. The recursive calls result in the printing of the values 5, 4, 3, 2, and 1 in that order.

Test: Functions - 1 - Question 26

What will be the output of the following code?

#include <iostream>

int myFunction(int x) {
    if (x <= 1)
        return x;
    
    return myFunction(x - 1) + myFunction(x - 2);
}

int main() {
    int result = myFunction(5);
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 26

The code defines a recursive function myFunction that calculates the Fibonacci sequence. The function takes an integer x and returns the sum of the two previous Fibonacci numbers. In main, myFunction is called with an argument of 5. The recursive calls result in the calculation of the 5th Fibonacci number, which is 8. The value 8 is then printed.

Test: Functions - 1 - Question 27

What will be the output of the following code?

#include <iostream>

int myFunction(int x) {
    if (x <= 0)
        return 1;
    
    return myFunction(x - 1) * x;
}

int main() {
    int result = myFunction(0);
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 27

The code defines a recursive function myFunction that takes an integer x. Inside the function, it checks if x is less than or equal to 0 and returns 1 if true. Otherwise, it multiplies x with the result of the recursive call with x decremented by 1. In main, myFunction is called with an argument of 0. Since the initial value of x is 0, the function immediately returns 1. The value 1 is then printed.

Test: Functions - 1 - Question 28

What will be the output of the following code?

#include <iostream>

void myFunction(int& x) {
    x *= 2;
}

int main() {
    const int value = 10;
    myFunction(value);
    std::cout << value << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 28

The code defines a function myFunction that takes an integer reference x and doubles its value. In main, a constant integer variable value is declared and assigned a value of 10. Since value is declared as const, its value cannot be modified. The attempt to modify value inside myFunction results in a compilation error. The original value of value, 10, is then printed.

Test: Functions - 1 - Question 29

What will be the output of the following code?

#include <iostream>

void myFunction(int* x) {
    *x = 20;
}

int main() {
    int value = 10;
    myFunction(&value);
    std::cout << value << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 29

The code defines a function myFunction that takes an integer pointer x and modifies the value pointed to by x to 20. In main, an integer variable value is declared and assigned a value of 10. The address of value is passed to myFunction, attempting to modify its value to 20. However, value is not declared as a pointer, and passing its address to myFunction results in a compilation error.

Test: Functions - 1 - Question 30

What will be the output of the following code?

#include <iostream>

int myFunction(int x) {
    if (x == 0)
        return 0;
    
    return x + myFunction(x - 1);
}

int main() {
    int result = myFunction(0);
    std::cout << result << std::endl;
    return 0;
}

Detailed Solution for Test: Functions - 1 - Question 30

The code defines a recursive function myFunction that takes an integer x. Inside the function, it checks if x is equal to 0 and returns 0 if true. Otherwise, it adds x to the result of the recursive call with x decremented by 1. In main, myFunction is called with an argument of 0. Since the initial value of x is 0, the function immediately returns 0. The value 0 is then printed.

70 videos|45 docs|15 tests
Information about Test: Functions - 1 Page
In this test you can find the Exam questions for Test: Functions - 1 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Functions - 1, EduRev gives you an ample number of Online tests for practice

Top Courses for EmSAT Achieve

70 videos|45 docs|15 tests
Download as PDF

Top Courses for EmSAT Achieve