Tuesday, November 8, 2022

what is function in c | syntax | definition | example

Function in C

  • A function are sub program , it is not complete program whereas it is a part of the program.
  • It has a name for indentification.
  • All function name must be unique.
  • One can define functions in any sequence

Benefits Of Functions

  • Function is used to proper utilization of memory.
  • Once function defined can be used many times.
  • Avoid repetition of code.
  • Divide complex problem in to simpler ones.
  • Increases program readability.
  • Reduces chances of error.

Function Type

    1. Pre-defined function/ buit in function/ library function
    2. User defined functions

 Pre-defined Function

In c language threre are multiple library function.
exam- clrscr() , getch() , printf() , scanf() , sqrt() , pow() , strlen() 

User Defined Function

C program allow us to define function according to our needs.
These function are made for code re-usability and saving time.

It consist of 3 part

    1. Function definition
    2. Function call
    3. Function declaration/ function prototype

Function Definition in C

Function definition contain block of code to perform certain task.

Function Call

In order use the function we need invoke it at a required place in program.

Function Pro-type

It gives information to the compiler about the function structure or definition.

Function Pro-type contain 3 part

    1. Return type
    2 Fuction name
    3 Arguments
Exam- Return-type FunctionName (Arguments) 
 

MCQ

1. _________ is a named independent or self contained block of C code that performs a specific task.
       1. Operator
       2. Array
       3. Function
       4. Structure
2. A function is named with a unique name .
       1. True
       2. False
3. The functions which we create for specific task is know as ......................... functions.
       1. Library
       2. User-defined
       3. Predefined
       4. None
4. Which of the following header file is used for character handling functions (eg isupper() , isalpha() ).
       1. stdio.h
       2.conio.h
       3. ctype.h
       4. stdlib.h
5. All the functions available in math.h library take ............. as an argument.
       1. int 
       2. double
       3. void
    ` 4. char
6. In which method, during function call actual paramenter value copied and passed to formal parameter. Changes made to the format parameters do not affect the actual parameters.
       1. Call by value
       2. Call by reference
       3. both
       4. None
7. The keyword used to transfer control from a function back to the calling function is ...............
       1. Switch
       2. return
8. Every C program should contain which function ?
       1. printf()
       2. show()
       3. main()
       4. scanf()
9. What is the limit for number of functions in a C Program?
       1. 16
       2. 31
       3. 32
       4. No limit
10. What are the type of function in C Language?
       1. Library Function 
       2. User Defined Functions
       3. Both Library and User Defined
       4. None of the above


 
























No comments: