Skip to main content

Functions in C programming

     A function is defined as a self contained block of statements that performs a particular task. This is a logical unit composed of a number of statements grouped into a single unit. It can also be defined as a section of a program performing a specific task. [Every C program can be though of as a collection of these functions.] Each program has one or more functions. The function main(0 is always present in each program which is executed first and other functions are optional.

 Advantages of using Functions:
The advantages of using functions are as follows:

1. Generally a difficult problem is divided into sub problems and then solved. This divide and conquer technique is implemented in C through functions. A program can be divided into functions, each of which performs some specific task. So, the use of C functions modularizes and divides the work of a program.
2. When some specific code is to be used more than once and at different places in the program, the use of function avoids repetition of that code.
3. The program becomes easily understandable. It becomes simple to write the program and understand what work is done by each part of the program.

4. Functions can be stored in a library and reusability can be achieved.

Comments

Popular posts from this blog

Passing arrays to functions in C programming

Like any other variables, we can also pass entire array to a function. An array name can be named as an argument for the prototype declaration and in function header. When we call the function no need to subscript or square brackets. When we pass array that pass as a call by reference because the array name is address for that array. /* Program to illustrate passing array to function */ #include<stdio.h> void display(int) ; /* function prototype */ main( ) { int num[5] = {100, 20, 40, 15, 33, i ; clrscr( ) ; printf (“\n The content of array is \n”) ; for (i=0; i<5; i++) display (num[i]) ; /*Pass array element fo fun */ getch{ } ; } void display(int n) { printf (“\t%d”, n ) ; } Output:     The content of array is 100      20       40       15 3 /* Program to read 10 numbers from keyboard to store these num into array and then c...

Explanation of Graphics in C programming

   The header file graphics.h should be included to use graphics related built in functions. Again, the variable gDriver is an integer variable that specifies graphics driver to be used. Device drivers are small programs which talk directly to the hardware. Graphics drivers are a subset of device drivers and are applicable only in the graphics mode. The initialization of this variable to DETECT is to set another variable gMode to the highest resolution available for the detected driver.  The value of this variable gDriver may be another than DETECT (e.g. 1 for CGA, 9 for VGA.). The variable gMode is an integer that specifies initial graphics mode.       The built in function initgraph() is for graphics initialization. The syntax for this is as   initgraph(&graphics_driver, &graphics_mode, path_to_driver);   path_to_driver specifies the directory path where initgraph() looks for graphics drivers ( .BGI files). Thi...

BIOS

BIOS stands for Basic Input Output System. It is is kind of OS pre- attached in the system Design to detect every I/O devices It holds basic drivers -checks all I/O devices -Loads main OS -Responsible for starting System switched on manufactured by AMI,Phonix,award,Baiostar POST error test, boots trap load, BIOS is unintrusive system. CMOS and BIOS are two different components of the motherboard. CMOS work as storage if BIOS. A basic software program containing all BIOS is permanently stored in the ROM. every essencial holds program Tresh passing without knowinig is called intrusive.