Functions in C are essential building blocks that allow you to break down complex programs into smaller, manageable tasks. Understanding MCQs on Functions in C helps you master function creation, calling, parameter passing, and recursion. These concepts are vital for improving coding skills and preparing for exams or interviews.
int function_name();function_name()void function_name;define function_name();voidcharintfloatreturn_type function_name(parameters) { /* code */ }function_name(parameters) { /* code */ }int main(parameters) { /* code */ }void function_name(parameters) /* code */voidvoid and int return types?
void returns a value, while int does notint returns an integer, while void returns nothingint and one int parameter?
int func(int x);void func(int x);int func(void);float func(int x);staticconstvolatileexternNULLint f(int x) { return x + 1; }void f() { printf("Hello"); }int f(int x) { return f(x - 1); }void f() { return; }static declarationstaticinlineexternglobalprintf and scanf?
math.hstdio.hstring.hstdlib.hsqrt function is available in which library?
stdio.hstring.hmath.hstdlib.hmath.h is used to calculate the power of a number?
sqrt()pow()exp()log()malloc()printf()strcpy()scanf()stdio.hstdlib.hmath.hstring.hstdlib.hmath.hstdio.hstring.hstrlen()strcpy()strcat()strstr()rand()random()strcat()sqrt()ceil and floor functions?
stdio.hmath.hstdlib.hstring.hcos()sin()tan()log()strstr()strchr()strrchr()strcpy()memset and memcpy?
stdio.hstdlib.hstring.hmath.hprintf()fgets()fputs()strcpy()strcpy()strcmp()strcat()strstr()return()break()exit()terminate()void f(int);int f();float f(char, int);voidintcharfloate raised to a given power?
pow()sqrt()exp()log()voidemptyNULLnoneif-elsebase casewhile loop46. Which function in math.h returns the remainder of a division operation?
remainder()modf()mod()fmod()47. Which type of variable retains its value between function calls?
48. Which function would you use to get the square root of a number?
power()sqrt()log()exp()49. Which keyword is used to prevent a function from modifying a variable passed by reference?
finalstaticconstreadonly50. What is the purpose of the void keyword in a function declaration?
| Q.No | Answer |
|---|---|
| 1 | a) Function definition and declaration are necessary for function usage. |
| 2 | c) The function prototype declares a function without defining it. |
| 3 | d) Arguments are passed to functions in C by value. |
| 4 | c) void is used to declare a function that returns no value. |
| 5 | a) Local variables are accessible only within the function they are declared in. |
| 6 | b) Global variables are accessible throughout the program. |
| 7 | b) Local variables have automatic storage duration by default. |
| 8 | b) Static variables retain their value between function calls. |
| 9 | b) The lifetime of a static variable is the lifetime of the program. |
| 10 | a) Recursion is when a function calls itself. |
| 11 | c) Recursive functions must have a base case to stop recursion. |
| 12 | b) Infinite recursion occurs when there’s no base case. |
| 13 | a) inline suggests the compiler to insert the function’s code at each call site. |
| 14 | a) Inline functions can be defined using the inline keyword. |
| 15 | c) Inline functions can help reduce function call overhead. |
| 16 | a) printf is a library function in stdio.h. |
| 17 | a) sqrt is a function from math.h. |
| 18 | d) The function pow() computes power. |
| 19 | a) exit() function terminates the program. |
| 20 | c) The main function is the entry point of a C program. |
| 21 | b) int function return type signifies returning an integer value. |
| 22 | b) The return statement is used to return a value from a function. |
| 23 | a) scanf is used for input in C. |
| 24 | b) void means the function has no parameters. |
| 25 | b) Global variables are declared outside all functions. |
| 26 | b) int, float, and double are standard data types in C. |
| 27 | c) Constants are defined with #define or const. |
| 28 | b) The scope of an identifier determines its visibility. |
| 29 | a) register suggests storing a variable in a CPU register. |
| 30 | b) extern is used to declare a global variable in another file. |
| 31 | c) A function prototype is declared before calling the function. |
| 32 | a) A function declaration specifies the function name and parameters. |
| 33 | a) void means the function returns no value. |
| 34 | b) Functions can have multiple parameters. |
| 35 | a) Functions are defined with a return type, name, and parameters. |
| 36 | b) Functions are called using the function name and arguments. |
| 37 | c) string.h is required for memory manipulation functions like memset. |
| 38 | b) fgets() reads a line of text and stores it in a character array. |
| 39 | b) strcmp() compares two strings. |
| 40 | c) exit() is used to terminate a program. |
| 41 | d) All of the above are correct prototypes. |
| 42 | a) void specifies a function with no return value. |
| 43 | c) exp() calculates e raised to a given power. |
| 44 | a) Use void for no parameters in a function. |
| 45 | b) A recursive function needs a base case. |
| 46 | d) fmod() returns the remainder of a division. |
| 47 | c) Static variables retain their value between calls. |
| 48 | b) sqrt() calculates the square root. |
| 49 | c) const prevents modification of a variable. |
| 50 | a) void specifies no return type for a function. |