Back to Browse

Functions in C. Type of Functions. Recursive Function

150 views
Nov 16, 2023
16:40

Define #Function. What are the benefits of function? Function is Organized block of statements that perform particular task -Function is reusable code that make program easier -Function return value Benefits of Functions 1. Reusability: Function write once and use multiple time 2. Reduce Code: No need to write the code for the same task 3. Modualarity: Functions divide the large program into small manageable code 4. Hiding information: Function definition can be hidden in the header file. 5. Improve Code Readability: Organized modular approach of function improve the code understanding. 6. Enhance maintainability: Function enhance maintenance of program. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ User Defined Function. Functions in c are of two types. One is Predefined or Built-in function and another is user defined functions. Every function used in C Language has three things 1. #FunctionDeclaration: The function declaration specifies the function's name, return type, and parameter list. 2. #FunctionDefinition: The function definition contains the code that performs the function's task. 3. #FunctionCall: The function call invokes the function's execution, passing any required input parameters. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ What do you understand by Function Declaration? The function declaration specifies the function's name, return type, and parameter list. Function declaration must be before the function call. It tell the compiler about 1. Function name: It must be unique in the program and can not be the name of Library or inbuilt function like printf, main, getch etc. 2. Return type: Every function must has return type. If a function does not return nothing than it must be void. 3. Parameters: It is in the parentheses ( ). It has number of parameters with data type. Example: int sum(int a, int b); Function name is sum Return Type is int and Two parameter a and b, both have of type int. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Explain type of Functions according to return type and parameter. On the bases of return type and parameters Functions are categorized into Four types 1. Function without Return type and without Parameter void fun1( ) 2. Function without Return type and with Parameters void fun2(int a, int b) 3. Function with Return type and without Parameters int fun3( ) 4. Function with Return type and Parameter int fun4(int a, int b) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ What is Recursion? What are the Conditions for recursion? What are the advantages and disadvantages of Recursion. Recursion is a programming technique where a function calls itself. Recursion is a powerful and versatile programming technique that can be used to solve a wide variety of problems. Recursion has two conditions 1. Function must have stopping condition 2. Function must calls itself Advantages: 1. Reduce code: Recursion reduce the code 2. Less storage: Less memory used 3. Divide and Conquer Approach: Recursive function calls itself and divide the problem in automotive sub functions 4. Readability: It improve the programmer readability Disadvantages 1. Stack overflow: Multiple calls of Recursive function is store in stack. There are chances of Stack overflow when stopping condition is not defined clearly 2. Complexity: Recursive functions are self calling function that increase the complexity. Debugging Problem: Debugging is difficult 3. Less efficient: It increase the Memory overload Examples 1. Factorial of number using Recursive Function 2. Fibonacci series using Recursive Function 3. Sum of digits of any number using Recursive Function #CPrograming The purpose of the video to provide help to studnets, who are unable to attend the regular Classes.

Download

0 formats

No download links available.

Functions in C. Type of Functions. Recursive Function | NatokHD