Example program for pointer to function in C C++

Example program for pointer to function in C C++

Pointer और इसके कार्य करने के तरीके को आधिक जानने के लिए देखें यह पोस्ट—Pointers in C

C Language में Pointer क्या प्रयोग करते हुए किसी Function को कैसे point किया जा सकता है जानने के लिए देखें—Pointer to function

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

Example program for pointer to function in C

#include<stdio.h>
void sum(int x,int y);
int main()
{
    int a=0,b=0;
    void (*ptr) (int,int);
    ptr=sum;
    printf("Enter a b: ");
    scanf("%d%d",&a,&b);
    ptr(a,b);
    return 0;
}
void sum(int x,int y)
{
    printf("a = %d\n",x);
    printf("b = %d\n",y);
    printf("Sum = %d\n",x+y);
}

Example program for pointer to function in C++

#include<iostream>
using namespace std;
void sum(int x,int y);
int main()
{
    int a=0,b=0;
    void (*ptr) (int,int);
    ptr=sum;
    cout<<"Enter a b: ";
    cin>>a>>b;
    ptr(a,b);
    return 0;
}
void sum(int x,int y)
{
    cout<<"a = "<<x<<endl;
    cout<<"b = "<<y<<endl;
    cout<<"Sum = "<<x+y<<endl;
}

Output of Example program for pointer to function in C C++

Example program for pointer to function in C C++

Other important function based programs in C C++

  1. Sum of two numbers using function
  2. Average of three numbers using function
  3. Swapping using function call by value
  4. Swapping using function call by reference
  5. Passing array as function argument
  6. Passing structure as function argument
Share it to:

Example program passing structure as function argument C C++

Example program passing structure as function argument C C++

C Language में Pointer क्या प्रयोग करते हुए किसी Function को कैसे point किया जा सकता है जानने के लिए देखें—Pointer to function

C Language में उपलब्ध विभिन्न प्रकार के Pointers और उनके उपयोग को जानने के लिए देखें—Types of Pointer in C

C के विभिन्न control statements को जानने के लिए देखें— Control statements in C

Example program passing structure as function argument C

#include<stdio.h>
struct student
{
    char grade;
    int marks;
    float per;
};
void display(struct student);
int main()
{
    struct student s;
    printf("Enter grade  : ");
    scanf("%c",&s.grade);
    printf("Enter marks  : ");
    scanf("%d",&s.marks);
    printf("Enter Percent: ");
    scanf("%f",&s.per);
    display(s);
    return 0;
}
void display(struct student s)
{
    printf("Grade  = %c\n",s.grade);
    printf("Marks  = %d\n",s.marks);
    printf("Percent= %f\n",s.per);
}

Example program passing structure as function argument C++

#include<iostream>
using namespace std;
struct student
{
    char grade;
    int marks;
    float per;
};
void display(struct student);
int main()
{
    struct student s;
    cout<<"Enter grade  :  ";
    cin>>s.grade;
    cout<<"Enter marks  :  ";
    cin>>s.marks;
    cout<<"Enter percent:  ";
    cin>>s.per;
    display(s);
    return 0;
}
void display(struct student s)
{
    cout<<"Grade    = "<<s.grade<<endl;
    cout<<"Marks    = "<<s.marks<<endl;
    cout<<"Percent  = "<<s.per<<endl;
}

Output of Example program passing structure as function argument C C++

Similar C C++ function example programs

  1. Sum of two numbers using function
  2. Average of three numbers using function
  3. Swapping using function call by value
  4. Swapping using function call by reference
  5. Passing array as function argument
  6. Pointer to Function
Share it to:

Example program passing array as function argument in C C++

Example program passing array as function argument in C C++

C Language में Pointer क्या प्रयोग करते हुए किसी Function को कैसे point किया जा सकता है जानने के लिए देखें—Pointer to function

C में फाईल क्या होता है इसे क्यो बनाया जाता है यह कितने प्रकार का होता है जानने के लिए देखें—Introduction to File

C-Language में function recursion किसे कहते है और इसकी क्या उपयोगिता है जानने के लिए देखें— Recursion in C

Example program passing array as function argument in C

#include<stdio.h>
void display(int[],int);
int main()
{
    int a[5],i=0;
    printf("Enter values: ");
    for(i=0;i<5;i++)
    scanf("%d",&a[i]);
    display(a,5);
    return 0;
}
void display(int a[], int n)
{
    int i=0,sum=0;
    for(i=0;i<n;i++)
    {
        printf("Element = %d\n",a[i]);
        sum=sum+a[i];
    }
    printf("Sum = %d",sum);
}

Example program passing array as function argument in C++

#include<iostream>
using namespace std;
void display(int[],int);
int main()
{
    int a[5],i=0;
    cout<<"Enter values: ";
    for(i=0;i<5;i++)
    cin>>a[i];
    display(a,5);
    return 0;
}
void display(int a[], int n)
{
    int i=0,sum=0;
    for(i=0;i<n;i++)
    {
        cout<<"Element = "<<a[i]<<endl;
        sum=sum+a[i];
    }
    cout<<"Sum = "<<sum;
}

Output of Example program passing array as function argument in C C++

Example program for passing array as function argument in C

Other function based example programs in C C++

  1. Sum of two numbers using function
  2. Average of three numbers using function
  3. Swapping using function call by value
  4. Swapping using function call by reference
  5. Passing structure as function argument
  6. Pointer to Function
Share it to:

Swap values of two variable function call by reference program in C C++

Swap values of two variable function call by reference program in C C++

C Language में Character Array या String किसे कहते है जानने के लिए देखें हमारा यह पोस्ट— Strings in C

Function क्या है इसका प्रयोग क्यो किया जाता है यह कितने प्रकार का होता है जानने के लिए देखें—Functions in C

C Language में Structure क्या होता है और इसका प्रयोग क्यो किया जाता है जानने के लिए देखें—Structures in C

Swap values of two variable function call by reference program in C

#include<stdio.h>
void swap(int*,int*);
int main()
{
    int a,b;
    printf("Enter a b: ");
    scanf("%d%d",&a,&b);
    printf("Before swapping values in main a = %d b = %d\n",a,b);
    swap(&a,&b);
    printf("After swapping values in main a = %d b = %d\n",a,b);
}
void swap (int *a, int *b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
    printf("After swapping values in function a = %d b = %d\n",*a,*b);
}

Swap values of two variable function call by reference program in C++

#include<iostream>
using namespace std;
void swap(int*,int*);
int main()
{
    int a,b;
    cout<<"Enter a b: ";
    cin>>a>>b;
    cout<<"Before swapping values in main a = "<<a<<" b = "<<b<<endl;
    swap(&a,&b);
    cout<<"After swapping values in main a = "<<a<<" b = "<<b<<endl;
}
void swap (int *a, int *b)
{
    int temp;
    temp=*a;
    *a=*b;
    *b=temp;
    cout<<"After swapping values in function a = "<<*a<<" b = "<<*b<<endl;
}

Output of Swap values of two variable function call by reference program in C C++

Callbyref program output in C CPP

Important function programs in C C++

  1. Sum of two numbers using function
  2. Average of three numbers using function
  3. Swapping using function call by value
  4. Passing array as function argument
  5. Passing structure as function argument
  6. Pointer to Function
Share it to:

Swap values of two variable function call by value program in C C++

Swap values of two variable function call by value program in C C++

C Language के बारे में अधिक जानने के लिए देखें—Brief Introduction of C

C और C++ दोनों भाषाओं में महत्वपूर्ण अंतर क्या है जानने के लिए देखें—C vs C++

Function में call by value और call by reference क्या होता है जानने के लिए देखें—Call by value and reference

Swap values of two variable function call by value program in C

#include<stdio.h>
void swap(int,int);
int main()
{
    int a,b;
    printf("Enter a b: ");
    scanf("%d%d",&a,&b);
    printf("Before swapping values in main a = %d b = %d\n",a,b);
    swap(a,b);
    printf("After swapping values in main a = %d b = %d\n",a,b);
}
void swap (int a, int b)
{
    int temp;
    temp=a;
    a=b;
    b=temp;
    printf("After swapping values in function a = %d b = %d\n",a,b);
}

Swap values of two variable function call by value program in C++

#include<iostream>
using namespace std;
void swap(int,int);
int main()
{
    int a,b;
    cout<<"Enter a b: ";
    cin>>a>>b;
    cout<<"Before swapping values in main a = "<<a<<" b = "<<b<<endl;
    swap(a,b);
    cout<<"After swapping values in main a = "<<a<<" b = "<<b<<endl;
}
void swap (int a, int b)
{
    int temp;
    temp=a;
    a=b;
    b=temp;
    cout<<"After swapping values in function a = "<<a<<" b = "<<b<<endl;
}

Output of Swap values of two variable function call by value program in C C++

Callbyvalue program output in C CPP

Useful function programs in C C++

  1. Sum of two numbers using function
  2. Average of three numbers using function
  3. Swapping using function call by reference
  4. Passing array as function argument
  5. Passing structure as function argument
  6. Pointer to Function
Share it to:

Program to find average of three numbers using function in C C++

Program to find average of three numbers using function in C C++

C-Language में function recursion किसे कहते है और इसकी क्या उपयोगिता है जानने के लिए देखें— Recursion in C

Function में call by value और call by reference क्या होता है जानने के लिए देखें—Call by value and reference

C Language में Pointer क्या प्रयोग करते हुए किसी Function को कैसे point किया जा सकता है जानने के लिए देखें—Pointer to function

Program to find average of three numbers using function in C

#include<stdio.h>
float avg(int,int,int);
int main()
{
    int a,b,c;
    printf("Enter three numbers: ");
    scanf("%d%d%d",&a,&b,&c);
    printf("Average of numbers = %f",avg(a,b,c));
    return 0;
}
float avg(int x, int y, int z)
{
    return (x+y+z)/3.0;
}

Program to find average of three numbers using function in C++

#include<iostream>
using namespace std;
float avg(int,int,int);
int main()
{
    int a,b,c;
    cout<<"Enter three numbers: ";
    cin>>a>>b>>c;
    cout<<"Average of numbers = "<<avg(a,b,c);
    return 0;
}
float avg(int x, int y, int z)
{
    return (x+y+z)/3.0;
}

Output of Program to find average of three numbers using function in C C++

C C++ program to find average of three numbers using function

More function example programs in C C++

  1. Sum of two numbers using function
  2. Swapping using function call by value
  3. Swapping using function call by reference
  4. Passing array as function argument
  5. Passing structure as function argument
  6. Pointer to Function
Share it to:

Example program for functions in C C++ Sum of two numbers using function

Example program for functions in C C++ Sum of two numbers using function

Function क्या है इसका प्रयोग क्यो किया जाता है यह कितने प्रकार का होता है जानने के लिए देखें—Functions in C

Function में call by value और call by reference क्या होता है जानने के लिए देखें—Call by value and reference

C-Language में function recursion किसे कहते है और इसकी क्या उपयोगिता है जानने के लिए देखें— Recursion in C

Example program for functions in C

#include<stdio.h>
int sum(int,int);
int main()
{
    int a,b;
    printf("Enter two numbers: ");
    scanf("%d%d",&a,&b);
    printf("Sum of numbers = %d",sum(a,b));
    return 0;
}
int sum(int x, int y)
{
    return x+y;
}

Example program for functions in C++

#include<iostream>
using namespace std;
int sum(int,int);
int main()
{
    int a,b;
    cout<<"Enter two numbers: ";
    cin>>a>>b;
    cout<<"Sum of numbers = "<<sum(a,b);
    return 0;
}
int sum(int x, int y)
{
    return x+y;
}

Output of Example program for functions in C C++

Example program for functions in C C++

Related function example programs in C C++

  1. Average of three numbers using function
  2. Swapping using function call by value
  3. Swapping using function call by reference
  4. Passing array as function argument
  5. Passing structure as function argument
  6. Pointer to Function
Share it to: