FreePrograms


C language is a middle level language. It is a structured language. C language is a case sensitive language. All syntax written in c language is in lower case. C is the basis for C++.
  CONTACT US   ABOUT US   PRIVACY  DISCLAIMER

FREE C PROGRAMS 

What is C C vs C++ vs Java Program Structure Data Types in C Basic Rules of C & C++
Functions in C If, Else Conditions Loops in C Switch Case Arrays
Pointers Structures in C Strings in C Command Line Arguments Type Casting
Linked Lists Recursion Binary Trees Inheritance Multiple Inheritance
Templates File I/O Object Oriented Programming Data Structures in C C interview Questions

Functions in C

C function is that block of code which does one or some tasks with specified purpose.

Basic Structure of Functions

return_ data_type Name of function(arg1, arg2)
    data _type _declarations of arguments;
    {

       Body of Function

    }

This program has function named 'sum' which sums the value of two numbers and returns to the main function. 
 
;This Simple Program Calculates Factorial of Number.

#include <stdio.h> //header file

#include<conio.h>//header file

void factorial (int);

void factorial (int x)
{

    int k, no = 1;Variable Declaration

    for (i=1; k <=n; ++i)
         no *= i;

    printf(“Factorial of %d is %d\n”, n,no);

}


int main(void)
{

    int no = 0;

    printf(“Enter a no\n”);

    scanf(“%d”, &no);
    factorial (no);

    return 0;

}

What is Void?

void anyFunction(void)

The first void is the return type of the function, that is what will be returned when the function is called. Void simply indicates that the function does not return a value.

When we have to return a value we will write:

int add(int a, int b)
{
return (a +  b);
}

void can also be used in the function's parameter list to explicitly specify that we want the function to take no actual parameters when it is called as we can see above, the second void.

What is Recursion?

Functions and passing arguments

Call by Value

Call by Reference

Passing a pointer to an array to a function.

Call by Value vs Call by Reference. Difference between call by value and call by reference in C?

Simple C program demonstrating call by value and call by reference. Valued called is 10.

Output:

Call by Value

10               

Call by Reference

10                 

Pointers as Function Arguments

Swapping of two numbers.

 

COPYRIGHT 2009 ALL RIGHTS RESERVED FREECPROGRAMS.COM