2nd Year NotesComputer class 12th

2nd Year Computer Chapter 13 Functions In C

2nd Year Computer Chapter 13 Functions In C Question And Answer

Short And Simple Question And Answer

Q 1. What is modular programming?

Ans. Modular programming is a technique where a program is divided into independent parts or modules, each designed to perform specific tasks. Multiple programmers can develop different modules, accelerating program development. These modules are later combined to create a complete program.

Q 2. What is a function?

Ans. In structured programming, a program consists of multiple parts, with each part referred to as a module or function. Functions have unique names and are created to perform specific tasks. A function can be defined as “A named piece of code developed to perform a specific task.”

Q 3. Why are functions used?

Ans. Functions are used for various advantages, including:

  • Simplifying programming
  • Facilitating modifications
  • Aiding in debugging
  • Supporting code reuse
  • Eliminating duplicate code
  • Reducing programming time

Q 4. What are built-in functions?

Ans. Built-in functions, also known as library functions, are functions provided by the C language itself. These functions are stored in different header files. To use a built-in function in a program, the relevant header file is included in the program’s preprocessor directive.

Q 5. What are user-defined functions?

Ans. User-defined functions are functions written by the programmer to perform specific tasks tailored to the program’s requirements.

Q 6. What are function prototypes?

Ans. Function prototypes, also known as function declarations, provide essential information to the compiler about a function’s structure. They are necessary for the proper declaration of a function in a C language program and can be placed before the main() function or inside it.

Q 7. What is function definition?

Ans. A function performs a specific task by executing a set of instructions. Writing the set of statements for a function is referred to as function definition, which is typically done outside the main() function.

Q 8. What is a function header?

Ans. The first line of a function definition is called the function header and follows this syntax: “Return-Type Name(parameters).”

Q 9. What is function calling?

Ans. Function calling is the process of using a function in a program. It involves writing a statement that calls the function by its name, with any required parameters included in braces at the end of the statement. A semicolon is used to end the statement in which the function is called.

Q 10. What is a return statement?

Ans. The “return” keyword is used to send a value from the body of a called function back to the calling function. The statement where the “return” keyword is used is called a return statement, following this syntax: “return expression.”

Q 11. What are parameters?

Ans. Parameters, also known as arguments, are values provided to a function when it is called. These values are placed after the function name within parentheses. Parameters can be variables or constants, and multiple parameters are separated by commas.

Q 12. What is a local variable?

Ans. Local variables are variables declared inside the main() function, within any user-defined function, or in the header of a function definition. They are also referred to as automatic variables and are limited to the scope of the function where they are declared. The general syntax to declare a local variable is: “auto data-type variable-name;”

Q 13. What is a global variable?

Ans. Global variables are variables declared outside the main() function or any other function. They are also known as external variables and can be accessed by all functions in the program. Changes to the value of a global variable in one function are reflected in all other functions.

Q 14. What is the lifetime of a variable?

Ans. The lifetime of a local variable is restricted to the duration of the function where it is declared. These variables are created in memory when control enters the function and are destroyed when control exits, making their data inaccessible.

Q 15. What is the scope of a variable?

Ans. Local variables have limited scope and can only be used within the function where they are declared. Attempting to access a local variable outside of its scope generates a compiler error.

Q 16. What is the scope of a global variable?

Ans. Global variables have a broad scope and can be accessed in all modules of the program. They are accessible in the main() function as well as in all other user-defined functions.

Q 17. What is the lifetime of a global variable?

Ans. Global variables are created in memory when the program begins execution and persist until the program is terminated. Therefore, the lifetime of a global variable extends from the program’s start to its termination.

Related Articles

Back to top button
error: Content is protected !!
Enable Notifications OK No thanks