All Exams  >   Class 10  >   C++ Programming for Beginners  >   All Questions

All questions of C++ Functions for Class 10 Exam

Which of the following is important in a function?
  • a)
    Return type
  • b)
    Function name
  • c)
    Both return type and function name
  • d)
    The return type, function name and parameter list
Correct answer is option 'C'. Can you explain this answer?

Arjun Sengupta answered
The correct answer is option C: Both return type and function name.

Explanation:

A function is a block of code that performs a specific task. It is a reusable piece of code that can be called from different parts of a program. When defining a function, there are several important components that need to be considered:

1. Return Type:
The return type of a function specifies the type of value that the function will return after its execution. It indicates the data type of the value that the function will produce as output. The return type is declared before the function name and is specified using a data type such as int, float, char, etc. The return type is important because it determines how the function can be used and what kind of value it will provide to the calling code.

2. Function Name:
The function name is a unique identifier for a function. It is used to call the function and invoke its code. The function name should be chosen carefully to reflect the purpose or task that the function performs. It should be meaningful and descriptive, making it easier for programmers to understand its functionality. The function name is important because it allows other parts of the program to access and utilize the code within the function.

3. Parameter List:
In addition to the return type and function name, the parameter list is another crucial aspect of a function. Parameters are variables that are used to pass data into a function. They allow the function to accept input values that can be used in its code. The parameter list specifies the name and data type of each parameter, allowing the function to receive and process the provided values. The parameter list is important because it allows the function to be customized and adaptable to different situations by accepting different input values.

In conclusion, all three components - return type, function name, and parameter list - are important in a function. They work together to define the functionality and behavior of the function, allowing it to be called, executed, and produce desired output values.

Where should default parameters appear in a function prototype?
  • a)
    To the rightmost side of the parameter list
  • b)
    To the leftmost side of the parameter list
  • c)
    Anywhere inside the parameter list
  • d)
    Middle of the parameter list
Correct answer is option 'A'. Can you explain this answer?

Arjun Sengupta answered
Default parameters in a function prototype

Default parameters are used in programming languages to assign a default value to a function parameter if no argument is provided for that parameter when the function is called. This allows the function to be more flexible by providing a default behavior while still allowing the option to override that behavior by passing in a different argument.

The placement of default parameters in a function prototype is important as it affects how the function can be called and how the parameters are assigned. In the case of C++, the correct placement of default parameters is to the rightmost side of the parameter list, which is option 'A'.

Explanation:

When declaring a function prototype in C++, the default parameters should be specified in the function declaration. The general syntax for a function declaration with default parameters is as follows:

```
return_type function_name(parameter1 = default_value1, parameter2 = default_value2, ...)
```

The default parameters are assigned values that will be used if no arguments are provided for those parameters when the function is called. These values are typically constants or expressions.

Example:

Let's consider an example of a function prototype that calculates the area of a rectangle:

```cpp
double calculateArea(double length, double width = 1.0);
```

In this example, the `calculateArea` function has two parameters: `length` and `width`. The `width` parameter has a default value of `1.0`, meaning that if no argument is provided for `width` when the function is called, it will default to `1.0`.

The default parameter should always appear to the rightmost side of the parameter list. This is because default parameters are assigned from right to left. If a default parameter appears in the middle of the parameter list, it can lead to confusion as to which parameter the argument is assigned to.

Conclusion:

In summary, default parameters in a function prototype should be placed to the rightmost side of the parameter list. This ensures clarity and consistency in the function declaration and allows for the proper assignment of default values when the function is called.

Which is more effective while calling the functions?
  • a)
    call by value
  • b)
    call by reference
  • c)
    call by pointer
  • d)
    call by object
Correct answer is option 'B'. Can you explain this answer?

Kiran Reddy answered
In the call by reference, it will just passes the reference of the memory addresses of passed values rather than copying the value to new memories which reduces the overall time and memory use.

What happens when objects s1 and s2 are added?
string s1 = "Hello";
string s2 = "World";
string s3 = (s1+s2).substr(5);
  • a)
    Error because s1+s2 will result into string and no string has substr() function
  • b)
    Segmentation fault as two string cannot be added in C++
  • c)
    The statements runs perfectly
  • d)
    Run-time error
Correct answer is option 'C'. Can you explain this answer?

When objects s1 and s2 are added, the behavior depends on the programming language and the specific implementation.

If s1 and s2 are strings in most programming languages, the operation of adding them together would concatenate the two strings. This means that the resulting string would be a combination of the characters from s1 and s2.

For example, if s1 is "Hello" and s2 is "World", then adding s1 and s2 would result in the string "HelloWorld".

However, if s1 and s2 are objects of a custom class, the behavior of the addition operator would depend on how it is defined within the class. The addition operation might be overloaded to perform a specific action, such as combining the properties or performing a mathematical operation on the objects.

What is the scope of the variable declared in the user defined function?
  • a)
    whole program
  • b)
    only inside the {} block
  • c)
    the main function
  • d)
    header section
Correct answer is option 'B'. Can you explain this answer?

Amrutha Khanna answered
Scope of Variable in User Defined Function

Introduction:
In programming, the scope of a variable refers to the region in the code where the variable is recognized and can be accessed. It determines the accessibility and lifetime of a variable. The scope of a variable depends on where it is declared.

Variable Scope in User Defined Function:
The scope of a variable declared in a user-defined function is limited to the block of code within the function, denoted by the curly braces {}.

Explanation:
When a variable is declared inside a user-defined function, its scope is restricted to that function only. This means that the variable can only be accessed and used within the block of code defined by the function.

Example:
Let's consider the following example to understand the scope of a variable in a user-defined function:

```python
def my_function():
x = 5
print(x)

my_function()
print(x) # This will result in an error
```

In the example above, a variable named 'x' is declared and assigned a value of 5 inside the function 'my_function()'. The variable 'x' can be accessed and used within the function. However, if we try to access the variable 'x' outside the function, it will result in an error because the variable is not defined in the global scope.

Conclusion:
The scope of a variable declared in a user-defined function is limited to the block of code within the function. It cannot be accessed or used outside the function. This helps in encapsulating variables within functions and prevents naming conflicts with other variables in the program.

When we define the default values for a function?
  • a)
    When a function is defined
  • b)
    When a function is declared
  • c)
    When the scope of the function is over
  • d)
    When a function is called
Correct answer is option 'B'. Can you explain this answer?

Arjun Sengupta answered
When do we define the default values for a function?

The correct answer is option 'B': When a function is declared.

Explanation:

When a function is declared, we have the option to specify default values for its parameters. Default values are the values that are used by the function if no argument is provided for that parameter when the function is called.

Declaration of a function:

When we declare a function, we provide its name, parameters, and return type (if any). The declaration of a function is typically done before the function is called or defined. It tells the compiler about the existence and signature of the function.

Default values for function parameters:

When declaring the parameters of a function, we can assign default values to them. This means that if no value is provided for a particular parameter when the function is called, the default value assigned during the declaration will be used instead.

Example:

Consider the following function declaration:

```python
def greet(name, message="Hello"):
print(message, name)
```

In this example, the `greet` function has two parameters: `name` and `message`. The `message` parameter has a default value of "Hello". If we call the function without providing a value for `message`, it will use the default value.

Function call:

```python
greet("John") # Output: Hello John
```

In this function call, we only provide a value for the `name` parameter. Since no value is provided for the `message` parameter, it uses the default value of "Hello".

Conclusion:

In summary, default values for function parameters are defined when the function is declared. This allows the function to have optional parameters with pre-defined values, making it more flexible and convenient for the caller. When the function is called, it uses the default values for any parameters that are not provided with explicit values.

Pick the incorrect statements out of the following.
  • a)
    Operator overloading does not disturbs the precedence of operators
  • b)
    Arity of operators can be changed using operator overloading
  • c)
    No new operators can be created
  • d)
    All of the mentioned
Correct answer is option 'B'. Can you explain this answer?

Ashish Mehta answered
Operator Overloading and Arity of Operators

Operator Overloading:

Operator overloading is a feature in object-oriented programming languages that allows operators to have different meanings based on the context of their use. In other words, it is a way of giving special meaning to operators when they are used with user-defined data types.

Incorrect Statements:

The incorrect statement is option 'B', which states that the arity of operators can be changed using operator overloading. This statement is incorrect because operator overloading does not allow us to change the arity (number of operands) of operators. The arity of operators is fixed by the language specification, and it cannot be changed.

Correct Statements:

The correct statements are as follows:

- Operator overloading does not disturb the precedence of operators. This means that the order in which operators are evaluated remains the same even if we overload them with new meanings.
- No new operators can be created using operator overloading. We can only overload the existing operators with new meanings.
- Overloaded operators must have at least one operand that is a user-defined data type. This is because the purpose of operator overloading is to provide special meaning to operators when they are used with user-defined data types.

Conclusion:

In conclusion, operator overloading is a powerful feature that allows us to give special meaning to operators when they are used with user-defined data types. However, it does not allow us to change the arity of operators or create new operators.

What will be the output of the following C++ code?
#include<iostream>
using namespace std;
 
int fun(int x = 0, int y = 0, int z)
{  return (x + y + z); }
 
int main()
{
   cout << fun(10);
   return 0;
}
  • a)
    10
  • b)
    0
  • c)
    Error
  • d)
    Segmentation fault
Correct answer is option 'C'. Can you explain this answer?

Kiran Reddy answered
Default arguments should always be declared at the rightmost side of the parameter list but the above function has a normal variable at the rightmost side which is a syntax error, therefore the function gives an error.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
 
int fun(int=0, int = 0);
 
int main()
{
  cout << fun(5);
  return 0;
}
int fun(int x, int y) { return (x+y); }
  • a)
    -5
  • b)
    0
  • c)
    10
  • d)
    5
Correct answer is option ''. Can you explain this answer?

Mohit Menon answered
Code Explanation
The provided C++ code includes a function with default parameters and demonstrates how function overloading works.
Code Breakdown
- Function Declaration:
cpp
int fun(int=0, int=0);
- This line declares a function `fun` that takes two integer parameters, both of which have default values of `0`.
- Main Function:
cpp
int main() {
cout < />
return 0;
}
- The `main` function calls `fun(5)`, passing `5` as the first argument. Since only one argument is provided, the second parameter `y` will take its default value of `0`.
- Function Definition:
cpp
int fun(int x, int y) {
return (x + y);
}
- This defines the function `fun`, which adds its two parameters, `x` and `y`, and returns the result.
Output Calculation
- When `fun(5)` is called:
- `x` is assigned `5`
- `y` takes the default value of `0`
- Therefore, the expression `x + y` evaluates to:
- `5 + 0 = 5`
Conclusion
- The output of the code will be `5`, making the correct answer option d) 5.
This illustrates how default parameters in C++ can simplify function calls by allowing certain arguments to be omitted while still providing meaningful outputs.

An inline function is expanded during ______________
  • a)
    compile-time
  • b)
    run-time
  • c)
    never expanded
  • d)
    end of the program
Correct answer is option 'A'. Can you explain this answer?

Inline functions

An inline function is a function that is expanded during compile-time. It is a programming construct that allows the compiler to insert the code of a function directly into the calling code, rather than making a function call. This can improve the performance of the program by reducing the overhead of function calls.

Compile-time expansion

When a function is declared as inline, the compiler replaces each function call with the actual code of the function. This process is known as expansion or inlining. The expansion occurs during the compilation phase of the program.

Advantages of inline functions

Inline functions have several advantages, including:

1. Performance improvement: Inline functions eliminate the overhead of function calls, such as pushing and popping the stack, passing parameters, and returning values. This can result in faster execution times for small, frequently called functions.

2. Code size reduction: By expanding the function code inline, the compiler can eliminate the need for a separate function call, reducing the size of the compiled program.

3. Improved optimization: By having access to the complete function code during compilation, the compiler can perform better optimizations, such as loop unrolling or constant propagation.

When to use inline functions

Inline functions are most effective for small, simple functions that are called frequently. They are commonly used for getter and setter functions, as well as simple mathematical operations.

Limitations of inline functions

Inline functions have some limitations:

1. Code bloat: If an inline function is called in multiple places, the expanded code will be duplicated at each call site, potentially increasing the size of the program.

2. Compiler discretion: The decision to inline a function is ultimately up to the compiler. It may choose not to inline a function if it determines that the benefits do not outweigh the costs.

3. Recursive functions: Recursive functions cannot be declared as inline, as they require multiple instances of the function to be active simultaneously.

In conclusion, inline functions are expanded during compile-time, allowing the compiler to insert the function code directly into the calling code. This can improve performance and reduce code size, but it is important to consider the limitations and use inline functions judiciously.

Which of the following is the default return value of functions in C++?
  • a)
    int
  • b)
    char
  • c)
    float
  • d)
    void
Correct answer is option 'A'. Can you explain this answer?

Riddhi singh answered
Default Return Value of Functions in C

In C programming language, a function is a collection of statements that perform a specific task. When a function is called, it can return a value to the calling program. However, if a function does not explicitly return a value, the default return value is assumed to be an integer.

Default Return Value

The default return value of functions in C is an integer, which is denoted by the keyword "int". This means that if a function does not specify a return type, the compiler assumes that the function returns an integer value.

For example,

```c
#include

// function without return type
void greet() {
printf("Hello, World!\n");
}

// main function
int main() {
greet(); // calling greet function
return 0;
}
```

In the above code, the "greet" function does not specify a return type, so the default return type of "int" is assumed. However, since the function does not return any value, the return type is not important in this case.

Conclusion

In C programming language, the default return value of functions is an integer. It is important to specify the return type of a function if it returns a value to the calling program. If a function does not return a value, then the return type is not important.

 which of the following is used to terminate the function declaration?
  • a)
    :
  • b)
    )
  • c)
    ;
  • d)
    ]
Correct answer is option 'C'. Can you explain this answer?

The correct answer is option 'C' - a semicolon (;) is used to terminate the function declaration.

A function declaration is a statement that defines a new function in a program. It specifies the function's name, return type, and parameters, if any. The function declaration is followed by a block of code that defines the function's behavior.

To understand why a semicolon is used to terminate the function declaration, let's break down the components of a function declaration and their purpose:

1. Function name: This is the name given to the function, which will be used to call the function later in the program.

2. Return type: This specifies the type of value that the function will return when it is called. It can be any valid data type, such as int, float, char, void, etc.

3. Parameters: These are optional values that can be passed to the function when it is called. They allow the function to accept input and perform operations on it.

4. Function body: This is a block of code enclosed within curly braces ({}) that defines the behavior of the function. It contains the instructions and statements that will be executed when the function is called.

Now, let's look at the role of the semicolon in the function declaration:

- The semicolon is used to terminate the function declaration statement. It indicates the end of the declaration and separates it from the function body.

- Without the semicolon, the compiler would interpret the function declaration and the function body as a single statement, resulting in a syntax error.

- The semicolon is not used to terminate the function body itself. It is only used to terminate the declaration statement.

- After the function declaration, the function body is written inside curly braces and does not require a semicolon at the end. The function body contains the actual code that will be executed when the function is called.

In summary, the semicolon is used to separate the function declaration from the function body and terminate the declaration statement. It is an essential part of the syntax for defining functions in programming languages.

Which of the following operator can be overloaded?
  • a)
    ?:
  • b)
    ::
  • c)
    .
  • d)
    ==
Correct answer is option 'D'. Can you explain this answer?

Naveen Chawla answered
Overloading Operators in C++

In C++, operators can be overloaded, which means that their behavior can be redefined for specific classes or data types. This allows us to use operators with custom objects in a way that makes sense for our program's logic.

Among the given options (a, b, c, and d), the correct answer is option 'D' (==). The equality operator (==) can be overloaded in C++.

Explanation:

Operator overloading in C++ allows us to redefine the behavior of an operator for a specific class or data type. This means that when the overloaded operator is used with objects or variables of that class or data type, a custom-defined action will be performed.

The equality operator (==) is commonly used to compare the equality of two objects or variables. When used with built-in data types such as integers or floating-point numbers, it simply compares their values. However, when used with objects of a user-defined class, we can define our own criteria for equality.

By overloading the equality operator (==), we can define how two objects of a class should be compared for equality. This allows us to compare objects based on specific attributes or conditions that are meaningful for our program.

For example, let's say we have a class called "Person" with attributes like name and age. By overloading the equality operator (==), we can define that two Person objects are considered equal if their names and ages match.

```cpp
class Person {
public:
string name;
int age;

// Overloading the equality operator
bool operator==(const Person& other) {
return (name == other.name && age == other.age);
}
};

int main() {
Person person1;
person1.name = "John";
person1.age = 25;

Person person2;
person2.name = "John";
person2.age = 30;

if (person1 == person2) {
cout < "both="" persons="" are="" equal."="" />< />
} else {
cout < "persons="" are="" not="" equal."="" />< />
}

return 0;
}
```

In the above example, we have overloaded the equality operator (==) for the Person class. We have defined that two Person objects are considered equal if their names and ages match. In the main function, we create two Person objects with different ages but the same name. When we compare them using the overloaded equality operator, we get the output "Persons are not equal."

To summarize, the equality operator (==) is one of the operators that can be overloaded in C++. By overloading this operator, we can define custom criteria for comparing objects of a class for equality.

What are mandatory parts in the function declaration?
  • a)
    return type, function name
  • b)
    return type, function name, parameters
  • c)
    parameters, function name
  • d)
    parameters, variables
Correct answer is option 'A'. Can you explain this answer?

Understanding Function Declarations
In programming, a function declaration provides essential information about a function to the compiler. Let's explore the mandatory parts of a function declaration.
Mandatory Parts of a Function Declaration
- Return Type:
- This specifies the type of value that the function will return after execution. For example, it can be an integer, float, or void (indicating no return value).
- Function Name:
- This is the identifier used to call the function. It should be descriptive enough to convey the function's purpose and must follow naming conventions set by the programming language.
Optional Components
- Parameters:
- While parameters are important for passing data into the function, they are not mandatory. A function can be declared without parameters.
- Variables:
- Variables are used within the function's body and are not part of the function declaration itself.
Conclusion
Thus, the correct answer is option 'A': return type and function name are mandatory parts of a function declaration. Understanding these components is crucial for writing effective code, as they define how the function interacts with other parts of the program.
This foundational knowledge will empower students to build more complex functions confidently as they progress in their programming journey.

In case of non-static member functions how many maximum object arguments a binary operator overloaded function can take?
  • a)
    1
  • b)
    2
  • c)
    3
  • d)
    0
Correct answer is option 'A'. Can you explain this answer?

Sonam singh answered
Maximum object arguments for a binary operator overloaded function with non-static member functions:

When overloading a binary operator with a non-static member function, the function takes at least one object argument. The object on which the member function is called will be implicitly passed as the first argument. The operator function can also take additional arguments if needed.

Explanation:

In C++, binary operators like addition (+), subtraction (-), multiplication (*), division (/), etc., can be overloaded to work with objects of user-defined classes. When overloading these operators, we can define how the operator should behave when applied to objects of our class.

In the case of non-static member functions, the operator function is defined as a member function of the class. This means that the function is called on an object of the class and operates on that object.

For example, let's consider a class called "Number" with a member function for overloading the addition operator:

```
class Number {
int value;
public:
Number(int val) : value(val) {}

Number operator+(const Number& other) {
Number result(value + other.value);
return result;
}
};
```

In this example, the "+" operator is overloaded as a member function of the "Number" class. It takes one additional argument, which is another object of the same class. The operator function adds the values of the two objects and returns a new object with the result.

When using this overloaded operator, the function is called on the left-hand side object, and the right-hand side object is passed as an argument:

```
Number num1(5);
Number num2(10);
Number sum = num1 + num2;
```

In this case, the object "num1" is calling the overloaded "+" operator function, and the object "num2" is passed as an argument. The result is stored in the "sum" object.

Conclusion:

In the case of non-static member functions, a binary operator overloaded function can take a maximum of one additional object argument in addition to the implicit object on which the member function is called. Therefore, the correct answer is option 'A' - 1.

If an argument from the parameter list of a function is defined constant then _______________
  • a)
    It can be modified inside the function
  • b)
    It cannot be modified inside the function
  • c)
    Error occurs
  • d)
    Segmentation fault
Correct answer is option 'B'. Can you explain this answer?

Shabnam Shah answered
Explanation:

In programming, a constant is a value that cannot be altered or modified during the execution of a program. When an argument from the parameter list of a function is defined as constant, it means that the value of that argument cannot be changed within the function.

Reason:

The reason behind this is that when a constant argument is passed to a function, it is essentially being passed by value. This means that a copy of the value is being made and passed to the function, rather than a reference to the original value. As a result, any modifications made to the argument within the function will only affect the copy and not the original value.

Consequence:

As a consequence, if an attempt is made to modify a constant argument inside the function, it will result in a compilation error. The compiler will detect the attempt to modify a constant value and raise an error, indicating that the modification is not allowed.

Benefits:

Defining an argument as constant provides several benefits. It helps ensure the integrity of the original value by preventing unintentional modifications. It also allows the programmer to easily identify which arguments are not intended to be modified within the function, improving code clarity and readability.

Example:

Let's consider a simple example to understand this concept better:

```
void modifyValue(const int x) {
x = 5; // This will result in a compilation error
}

int main() {
int num = 10;
modifyValue(num);
return 0;
}
```

In this example, the function `modifyValue` takes an argument `x` which is defined as a constant. When we try to modify the value of `x` inside the function, a compilation error will occur. The error message will indicate that the modification of a constant value is not allowed.

Therefore, option B is the correct answer: It cannot be modified inside the function.

How many approaches are used for operator overloading?
  • a)
    1
  • b)
    2
  • c)
    3
  • d)
    4
Correct answer is option 'C'. Can you explain this answer?

Kiran Reddy answered
There are 3 different approaches used for operator overloading:
i. Overloading unary operator.
ii. Overloading binary operator.
iii. Overloading binary operator using a friend function.

Which of the following feature is used in function overloading and function with default argument?
  • a)
    Encapsulation
  • b)
    Polymorphism
  • c)
    Abstraction
  • d)
    Modularity
Correct answer is option 'B'. Can you explain this answer?

Arjun Sengupta answered
Polymorphism is the correct answer.



Explanation:



Polymorphism is a fundamental concept in object-oriented programming that allows objects to have different forms or behaviors. It enables a single interface to represent multiple types of objects. Two common ways to achieve polymorphism in programming are function overloading and function with default argument.

Function Overloading:


Function overloading is a feature in programming languages that allows multiple functions with the same name but different parameters or arguments. These functions can perform similar tasks but with different input types or numbers of arguments. The compiler determines which function to execute based on the arguments passed during the function call. Function overloading provides flexibility and code reusability.



For example, consider a function called calculateArea. We can define multiple versions of this function with different parameter lists, such as one that calculates the area of a rectangle and another that calculates the area of a circle. When we call the calculateArea function with the respective arguments, the appropriate version of the function will be executed based on the argument types.



Function with Default Argument:


A function with default arguments is a function that allows some of its parameters to have default values. If a value is not provided for those parameters during the function call, the default values are used instead. This feature provides flexibility and simplifies function calls by reducing the number of arguments required.



For example, consider a function called printMessage that takes two arguments: message and count. By providing a default value for the count parameter, such as 1, we can call the function with just the message argument. The function will use the default value for the count parameter if no value is specified explicitly.



In conclusion, both function overloading and functions with default arguments are examples of polymorphism, which is the ability of objects or functions to take on different forms or behaviors. They enhance code reusability and flexibility in programming.

In which of the following cases inline functions may not word?
i) If the function has static variables.
ii) If the function has global and register variables.
iii) If the function contains loops
iv) If the function is recursive
  • a)
    i, iv
  • b)
    iii, iv
  • c)
    ii, iii, iv
  • d)
    i, iii, iv
Correct answer is option 'D'. Can you explain this answer?

Avni rao answered
Explanation:

Inline functions are a way to improve the performance of a program by reducing the function call overhead. They are typically used for small, frequently used functions. However, there are certain cases where inline functions may not work properly.

i) If the function has static variables:
- Static variables are initialized only once and retain their values between function calls.
- If an inline function contains static variables, each time the function is called, the static variables will be initialized again, which can lead to unexpected behavior.
- Therefore, inline functions may not work correctly when they have static variables.

ii) If the function has global and register variables:
- Global variables are accessible throughout the program, and register variables are stored in CPU registers for faster access.
- If an inline function uses global or register variables, it may not work properly because these variables have a wider scope than the function itself.
- Inlining the function may cause conflicts with other parts of the program that also use the same global or register variables.

iii) If the function contains loops:
- Inline functions are expanded at the call site, which means the function code is inserted directly into the calling code.
- If the inline function contains loops, the loop code will be replicated at each call site, which can lead to code bloat and decreased performance.
- Therefore, inline functions may not be suitable for functions that contain loops.

iv) If the function is recursive:
- Recursive functions are functions that call themselves.
- Inline functions cannot be recursive because inlining would lead to an infinite loop where the function keeps calling itself repeatedly.
- Therefore, inline functions may not work for recursive functions.

Conclusion:
- Based on the above explanations, inline functions may not work properly in cases where the function has static variables, global and register variables, loops, or is recursive.
- Hence, the correct answer is option 'D' - i, iii, iv.

How many minimum number of functions should be present in a C++ program for its execution?
  • a)
    0
  • b)
    1
  • c)
    2
  • d)
    3
Correct answer is option 'B'. Can you explain this answer?

Minimum number of functions in a C program

In C programming language, a function is a self-contained block of code that performs a specific task. Functions are essential for organizing and modularizing code, and they are necessary for the execution of a C program.

Answer:
The correct answer is option 'B' - 1.

Explanation:
A minimum of one function should be present in a C program for its execution. This function is known as the main function. The main function is the entry point of a C program, and it is where the program execution starts.

The main function has a specific syntax and structure in C:

```
int main() {
// Code statements
return 0;
}
```

Inside the main function, you can write the code statements that define the behavior of your program. These statements can include variable declarations, calculations, input/output operations, and function calls.

The main function must have a return type of `int`, which indicates the status of the program execution. A return value of 0 usually indicates successful execution, while non-zero values indicate some error or abnormal termination.

Optional Additional Functions:
Although a C program can technically execute with just the main function, it is common to have additional functions in the program to perform specific tasks. These functions can be defined before or after the main function.

Having additional functions allows for code organization, reusability, and modularity. Functions can be called from within the main function or from other functions, enabling the program to perform complex operations by dividing them into smaller, manageable tasks.

Conclusion:
While a minimum of one function (the main function) is required for a C program's execution, additional functions can be included to enhance code structure and functionality. However, the main function is essential and serves as the entry point for the program.

Which is called ternary operator?
  • a)
    ?:
  • b)
    &&
  • c)
    |||
  • d)
    ===
Correct answer is option 'A'. Can you explain this answer?

Kiran Reddy answered
?: is called ternary operator because it separates three expressions. exp1 ? exp2 : exp3.

Chapter doubts & questions for C++ Functions - C++ Programming for Beginners 2025 is part of Class 10 exam preparation. The chapters have been prepared according to the Class 10 exam syllabus. The Chapter doubts & questions, notes, tests & MCQs are made for Class 10 2025 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests here.

Chapter doubts & questions of C++ Functions - C++ Programming for Beginners in English & Hindi are available as part of Class 10 exam. Download more important topics, notes, lectures and mock test series for Class 10 Exam by signing up for free.

Signup to see your scores go up within 7 days!

Study with 1000+ FREE Docs, Videos & Tests
10M+ students study on EduRev