250+ TOP MCQs on Inline and Answers

C Multiple Choice Questions & Answers (MCQs) on “Inline”.

1. Name the function whose definition can be substituted at a place where its function call is made _________
a) friends function
b) inline function
c) volatile function
d) external function
Answer: b
Clarification: The inline function, whose definitions being small can be substituted at a place where its function call is made. They are inlined with their function calls.

2. What will be the output of the following C code?

#include 
void inline func1(int a, int b) 
{
    printf ("a=%d and b=%dn", a, b);
}
int inline func2(int x)
{
    return x*x;
}
int main()
{
    int tmp;
    func1(1,4);
    tmp = func2(6);
    printf("square val=%dn", tmp);
    return 0;
}

a)

a=1 and b=4
square val = 36

b) a=4 and b=1
c) error
d) square val = 36
Answer: a
Clarification: The code shown above is an example of inline function. Both functions 1 and 2 are inline functions. Hence the output will be as shown in option

a=1 and b=4
square val = 36

.

3. What will be the error (if any) in the following C code?

#include 
void inline func1(float b) 
{
    printf ("%lfn",b*2);
}
int main() 
{
     inline func1(2.2);
     return 0;
}

a) No error
b) Error in statement: void inline func1(float b)
c) Error in statement: printf(“%lfn”,b*2);
d) Error in statement: inline func1(2.2);
Answer: d
Clarification: The keyword inline is used only with the function definition. In the code shown above it has been used with the function call. Hence there is an error in the statement: inline func1(2.2);

4. What will be the output of the following C code?

#include 
void inline f1(char b) 
{
    printf ("%dn",b);
}
int main() 
{
    f1('a');
    return 0;
}

a) a
b) 65
c) error
d) 97
Answer: d
Clarification: The definition of the function f1 is replaced with the function call. Since the format specifier used is %d, the ASCII value of the said character is printed. Hence the output of the code shown above is 97 (ASCII value of the alphabet ‘a’).

5. What will be the output of the following C code?

#include 
void inline func1(char b[10]) 
{
    printf ("%cn",b[2]);
}
int main() 
{
     func1("");
     return 0;
}

a) s
b) n
c) a
d) error
Answer: b
Clarification: In the code shown above, the definition of function func1 is replaced with its function call. The function prints the alphabet at the second index of the given string. Hence the output of this code is ‘n’.

6. The following C code results in an error. State whether this statement is true or false.

#include 
void f(double b) 
{
    printf ("%ldn",b);
}
int main() 
{
     inline f(100.56);
     return 0;
}

a) True
b) False
Answer: a
Clarification: The above code will result in an error because we have used the keyword inline in the function call. Had the keyword inline been used in the function definition, the code would not have thrown an error.

7. What will be the output of the following C code?

#include
static inline int max(int a, int b) 
{
  return a > b ? a : b;
}
main()
{
    int m;
    m=max(-6,-5);
    printf("%d",m);
}

a) -6
b) -5
c) Junk value
d) Error
Answer: b
Clarification: The code shown a replaces the definition of a function max with it’s function call. This function is used to print the bigger of the two arguments. Hence -5 is printed.

8. What will be the output of the following C code?

#include
#define inline
inline f(char a)
    {
        #ifdef inline
        printf("%c",a);
        #endif 
    }
main()
{
    f('a');
}

a) Error
b) a
c) No error but nothing will be printed as output
d) 97
Answer: b
Clarification: In the code shown above, we have defined identifier names inline using the macro #define. The output will be printed only if inline is defined. Since it is defined, ‘a’ is printed as output.

9. What will be the output of the following C code?

#include
extern inline int min(int a, int b) 
{
  return a < b ? a : b;
}
main()
{
    int m;
    m=min(3,-5);
    printf("%d",m);
}

a) Error
b) 3
c) -5
d) Junk value
Answer: a
Clarification: The above code will result in an error due to the statement: extern inline int min(int a, int b). The keyword ‘extern’ causes an error: undefined reference to min.

10. To have GCC inline the given function regardless of the level of optimization, we must declare the function with the attribute _________________
a) optimize_inline
b) packed_inline
c) always_inline
d) level_inline
Answer: b
Clarification: To have GCC inline the given function regardless of the level of optimization, we declare the function with the attribute always_inline.

  250+ TOP MCQs on Oxygen Uptake in Cell Cultures and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top