ankitweblogic logo
W e b t u t o r i a l s

C Tutorial

Programing Approach

Algorithm

Flow Chart

Define C

Define Programming

C - Syntax

Compiler vs Interpreter

C - Variables

C - Keywords

C - Data Types

C - Comments

Turbo C - Shortcut keys

C - Operators

Hierarchy of Operators

Ex: Arithmetic Operator

C - Formatting Output

Constant Variable

C - Escape Sequence

C - if , switch

Ex: If condition

Ex: Inc / Dec Operator

C - loops

Ex: Loops

C - Nesting Of loops

Ex: Nested Loops

Jumping Statements

C - Arrays 1D

C - Arrays 2D

C - Sorting

ASCII Value

Character I/O Function

C - String Functions

Ex: Strings

Array of Strings

C - Math Functions

User-defined Function

Exercise Function

C - Types of Functions

Storage Class

C - Header Files

C - Preprocessor

C - Pointers

C - Structures

C - Typedef

C - File Handling

Ex: File Handling

Command Line Argument

MCQ

C - Types of function

In C, when function is called with arguments, there are 2 ways to pass the arguments, i.e call by value and call by reference.

  1. Call by value When a function is called and value of a variable is passed via argument it is known as call-by-value. In this case, any changes made inside the function have no effect on the other functions.
  2. Call by Reference When a function is called and address of a variable is passed via argument it is known as call-by-reference. In this case, changes will reflect in the other functions.

Example 1: Call by value.

#include<stdio.h>
#include<conio.h>

void fun(int); //function declaration
void main()
{
    int a=10;
    clrscr();
    fun(a);  //function call
    printf("\nValue of A outside function is = %d",a);
    getch();
}
void fun(int a) //function definition
{
    a=20;
    printf("\nValue of A in function is %d",a);
}
Value of A in function is 20
Value of A outside function is 10
Value change inside function will NOT reflect in main function.

Example 2: Call by reference.

#include<stdio.h>
#include<conio.h>

void fun(int *); //function declaration
void main()
{
    int a=10;
    clrscr();
    fun(&a);  //function call
    printf("\nValue of A outside function is = %d",a);
    getch();
}
void fun(int *a) //function definition
{
    *a=20;
    printf("\nValue of A in function is %d",*a);
}
Value of A in function is 20
Value of A outside function is 20
Value change inside function will reflect in main function.

Recursion function

Recursion function call itself up to the condition is not satisfied. In recursion function we cannot use any loop only if condition is used.

Questions on Recursion:

  1. Find factorial using recursion function.
  2. #include<stdio.h>
    #include<conio.h>
    
    int fact( int n );
    
    int main()
    {
        int n, r;
        printf("Enter number");
        scanf("%d",&n);
        r = fact(n); //function call
        printf("Factorial = %d",r);
        getch();
    }
    
    int fact(int n)
    {
        static int a;
        if(n==1)
    	{
            return 1;
        }
        else
        {
            a = n * fact(n-1);
        }
        return a;
    }
  3. Find Greatest Common Divisor
  4. WAP to calculate x power n