Functions in C Short Questions with Answers


Functions in C Short Questions with Answers. This post for the students of Computer ICS Part 2 | Computer Science 2nd Year Chapter No.13 Functions in C. Find the most important and conceptual short questions with their answers for the final examination of intermediate for all boards of Punjab as well as Pakistan.

 

We tried our best to make / select the most important short questions with simple solution of this chapter i.e. Function in C, importance of functions of C language. This post covers the topics i.e., introduction to subprograms | functions | modules, built-in functions, user-defined functions, local and global variables & their scope, actual parameters (arguments), formal parameters, lifetime of the variables, function prototype, function calling, and function header.


functions in c short questions with answers, ics part 2


Chapter No.13: Functions in C

Short Questions with Answers


Q.1: What is Function OR Module OR Subprogram?

Answer:

A function is a self-contained piece of code with a specific purpose. Functions are the building blocks of C programs. They encapsulate pieces of code to perform specific operations. Functions allow us to accomplish the similar kinds of tasks over and over again without being forced to keep adding the same code into the program. These perform tasks that may need to be repeated many times.

 

Q.2: Differentiate between unstructured and structured programming?

Answer:

Unstructured Programming:

In unstructured programming, the entire logic of the program is implemented in a single module (function), which causes the program error-prone, difficult to understand, modify and debug.

Structured Programming:

In structured programming, the entire logic of the program is divided into a number of smaller modules, where each module (piece of code) implements a different functionality.

 

Q.3: Write some benefits of functions OR structured programming language?

Answer:

The following are some benefits of functions OR structured programming language:

  • Easier to understand and maintain the programs
  • Increase reusability of the code
  • Divide the workload by writing different functions
  • Ensure the parallel development of the software
  • Easy to debug the subprograms

 

Q.4: Differentiate between Built-in functions and User-defined functions:

Answer:

Built-in Functions:

Built-in functions are predefined functions that provide convenient ways to perform a variety of tasks. These functions are packaged in libraries. Through these functions we can easily access complex programming functionality. Examples of built-in functions are printf, scanf are defined in the library of stdio.h. Similarly, getch and getche functions are defined in the library of conio.h.

User-defined Functions:

A programmer may need to write his/her functions depending on the nature of the problem being solved. Such functions are called user-defined functions.

 

Q.5: What is a function prototype?

Answer:

A function prototype is a statement that provides the basic information that the compiler needs to check and use a function correctly. It specifies the parameters to be passed to the function, the function name, and the type of return value.

The general form of the function prototype is as follows:

return_type Function_Name (parameter_list);

 

Q.6: What is meant by calling a function?

Answer:

Function call is a mechanism is used to invoke a function to perform a specific task. A function call can be invoked at any point in the program. When the function call statement is executed, it transfers control to the function that is called. After the last statement in the function is executed, control returns to the calling function.

 

Q.7: What is the function header?

Answer:

A function header identifies the function followed by the body of the function between curly braces containing the executable code for the function.

The general form of function header:

return_type Function_Name(parameter_list)

{

Executable statement(s);

return expression;

}

 

Q.8: What is meant by return_type and parameter_list in function header?

Answer:

The return_type can be any valid data type. If the function does not return a value, the return type is specified by the keyword void. A function that has no parameter specifies the keyword void as its parameter list.

A function that has no parameter and does not return and value to the calling function will have the header:

void Function_Name (void)

 

Q.9: What are local variables and their scope?

Answer:

All variables which have been declared within a block or within a pair of curly braces are called local variables. The scope of a local variable is from the point in the program where it is declared until the end of the block containing its declaration.

 

Q.10: What is meant by lifetime of the variable?

Answer:

When the program executes, all variables are created in memory for a limited time period. They come into existence from the place where they are declared, and then they are destroyed. The duration in which a variable exists in the memory is called lifetime of the variable.

 

Q.11: What is the scope of variable?

Answer:

The scope of a variable refers to the region of a program in which it is accessible. The name of a variable is only valid within its scope. So a variable cannot be referred outside its scope.

 

Q.12: What are global variables and their scope?

Answer:

The variables which are declared outside all blocks i.e. outside the main() and all other functions are called global variables and have global scope. They are accessible from the point where they are declared until the end of the file containing them. They exist in memory from the start to the end of the program.

 

Q.13: What is meant by “Function without arguments”?

Answer:

A function that returns no value and no arguments are passed to them. The return type of such function is void and the parameter_list may either be empty or containing the keyword void.

A function that has no parameter and does not return and value to the calling function will have the header:

void Function_Name (void)

 

Q.14: What are the actual parameters OR arguments?

Answer:

Actual parameters or arguments are the values that are passed to a function when it is called or invoked.

 

Q.15: What are the formal parameters?

The term “parameter” sometimes called formal parameter is often used to refer to the variables as found in the function header or function prototype.

The parameters specified in the function header are called formal parameters or formal arguments of the function and their scope is the body of the function. These are also called dummy arguments

 

➤ Functions in C - MCQs Set-1
➤ Functions in C - MCQs Set-2
➤ Functions in C - Exercise Programs
➤ File Handling in C - MCQs
➤ File Handling in C - Short Questions
➤ Loop Constructs - MCQs
➤ Loop Constructs - Exercise Solution
➤ Loop Constructs - Short Questions
➤ Decision Constructs - MCQs
➤ Decision Constructs - Short Questions
➤ Decision Constructs - Exercise Programs

Post a Comment

Your feedback is highly appreciated and will help us to improve. So, please give your good suggestions.

Previous Post Next Post