Course Content
Detailed Content of Programming in C
0/1
Introduction
0/1
Structure of C program
0/1
Answers of ‘C’ Pointers Programs
0/1
About Lesson

What is Functions?

A Number of Statements Grouped into a Single Logical Unit is referred to as a ‘Function‘ which is made to Complete a Specific Task. A Program can be made of many functions but ‘main‘ is the ‘Function‘ whose statements are executed ‘First‘. Functions are mainly classified in two types:

  • User-Defined Function
  • Inbuilt Function

Types Of Functions:

1.User-Defined Function:

C‘ allows user to define functions according to your need. Each ‘function‘ has Call and Body. These ‘Functions‘ are known as User-Defined Function.

Suppose, you need to create a Circle and Color it depending upon the Radius and Color. You can create two ‘Functions‘ to solve this Problem.

  • createCircle() function
  • Color() function

2.In-built Function: 

The In-built Functions also called as predefined functions, because information regarding these ‘Functions‘ is already defined in Header Files.

Example of In-built Functions:

printf(), scanf(), getch(), gets(), puts(), sin(), cos(), pow(), getche(). are examples of In-built Functions. Each Function Contain pair of round brackets().


Characteristics Of Functions:

Functions in C exhibit several characteristics that are fundamental to their role in structuring code and facilitating modular programming. Here are the key characteristics of functions in C:

  1. Modularity:

    • Functions allow breaking down a program into smaller, more manageable modules.
    • Each function encapsulates a specific set of tasks, promoting modular design.
  2. Reusability:

    • Functions can be reused in different parts of a program or in multiple programs.
    • Once defined, a function can be called as many times as needed.
  3. Abstraction:

    • Functions provide a level of abstraction by hiding the implementation details from the calling code.
    • Users only need to know the function’s purpose and how to use it, not its internal workings.
  4. Return Type:

    • Functions have a return type that specifies the type of value they can return to the calling code.
    • The return type can be int, float, void, or any other valid data type.
  5. Parameters:

    • Functions can accept parameters (inputs) that influence their behavior.
    • Parameters allow functions to work with different sets of data and make them more versatile.
  6. Local Variables:

    • Functions can have local variables that are only accessible within the function’s scope.
    • Local variables provide isolation and prevent unintended interactions with variables in other parts of the program.
  7. Function Prototype:

    • Functions can be declared with a prototype, providing information about the function’s signature (return type, name, parameters).
    • Prototypes help the compiler verify the correct usage of functions before their actual implementation.
  8. Call by Value:

    • C uses “call by value” for parameter passing, which means the values of the actual parameters are passed to the function.
    • Changes to the parameters inside the function do not affect the original values in the calling code.
  9. Return Statement:

    • Functions use the return statement to send a value back to the calling code.
    • The return statement also terminates the function execution, transferring control back to the caller.
  10. Namespace:

    • Functions create a separate namespace for variables, preventing naming conflicts with variables in other parts of the program.
  11. No Nested Functions:

    • C does not support the direct nesting of functions within other functions.
    • Functions are defined at the global scope or within blocks.
  12. Recursive Calls:

    • Functions in C can be recursive, meaning they can call themselves.
    • Recursive functions are useful for solving problems that can be broken down into smaller, similar subproblems.

Understanding and leveraging these characteristics is crucial for writing well-organized, modular, and maintainable C code.