Posts

Showing posts from April, 2015

Student Help: How to add a user defined function to a library fu...

Student Help: How to add a user defined function to a library fu... : Here we are going to create a function for factorial of a the given number: Step 1: First create the definition of the program and...

how to create our own header files

Hello friends I am here with my post which is how to create your own header files but before start I would like to explain what a header file is and why it is used in our program. We all know that a program contain different library functions to perform the given job by user. A header file contains the definition of the functions which is included in that header file. Definition of a function tells the compiler that what operation that function have to perform or in what manner and how many number of argument it accept and how many argument it will return .the type of arguments everything about that function. There are number of header files used in c programming we just have to call as per as our requirement .header files are very useful so let’s make a header file of our own. Follow these steps: First of all create the definition of a function and save it with the extension .h (my_func.h) Example: int sum(int a,int b) { return(a+b); } ·          Now create a progr

DYNAMIC MEMORY ALLOCATION (DMA)

In programming we use some variables and to store those variables we used memory space to allocate some space for that variable .when we are using array we can use or allocate memory space dynamically means to allocate contiguous memory space during the program execution .means the way to reserve memory address at run time is called dynamic memory allocation or in short it refers as DMA. There are two functions used to allocate: Malloc():used for allocation of memory space at run time Syntax: int *ptr; Ptr=(int*)malloc(n*sizeof(int)); ·          Here ptr accepts the base address returned by the given statement. ·          Malloc is the function used for allocation of memory space. ·          N stands for number of elements ·          Sizeof return the size of the data type enclosed in the bracket Calloc():  is same as malloc() but there is a minor difference between this will be clear after watching this example: Syntax: int *ptr; Ptr=(int*)malloc(n,2); ·          Here ptr