ADDING FUNCTION TO THE LIBRARY

in our previous application we have created multiple function and use them on the same application fileBut in the real world scneario this is not a actual way of doing coding.

Suppose you are creating an application where we have 1000 functions in this case if we write all function in main file this will

1.increase the file size.

2.for searching some code you need to scroll a lot.

3.this makes code more clumsy.

4. since we are loading all functions this will hamper processing also.

To over come this problem we can use library and use these 1000 functions in new user defined library.

#include<stdio.h>

#include“sum.h”

void main()

{

  int a=10;

  int b=15;                                       //main.c

  int c=sum(a, b);

  printf(“%d”, c);

}

int sum(int a, int b)

{

  int c=a+b;                   //sum.c

  return c;

}

int sum(int , int);           //sum.h

Compiler:               o/p file name                     i/p file name

Gcc – 0                      main                                 main.c    sum.c

output ->  this will give main.exe on window

Execute     .\main.exe    window   or    .\main      linux

o/p 25

task   ->   write a program create two library and use them?

Data types

Integer chart

Compiler

Short

Int

Long

16 bit

2 byte

2 byte

4 byte

32 bit

2 byte

4 byte

4 byte

64 bit

2 byte

4 byte

4 byte

Short <   int     <  long

2 byte                  4 byte

 

Short int                     int                          long int

Short int a;                int a;                      long int a;

Or short a;                                                long a;