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 for string and pointer in C C++

Example program for string and pointer in C C++

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

C में Pointer और String एक दूसरे से कैसे संबंधित होते है और एक साथ कैसे प्रयोग में लाए जाते है जानने के लिए देखें—  Pointer and String

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

Example program for string and pointer in C

#include<stdio.h>
int main()
{
    char s1[20]="icomputernotes";
    char s2[20];
    char *p1="icomputernotes";
    char *p2;
    puts(s1);
    puts(p1);
    p2=p1;
    //s2=s1 will generate error
    puts(p2);
    p2="icomputernotes";
    //p2="icomputernotes" will generate error
    puts(p2);
    return 0;
}

Example program for string and pointer in C++

#include<iostream>
using namespace std;
int main()
{
    char s1[20]="icomputernotes";
    char s2[20];
    char *p1="icomputernotes";
    char *p2;
    cout<<s1<<endl;
    cout<<p1<<endl;
    p2=p1;
    //s2=s1 will generate error
    cout<<p2<<endl;
    p2="icomputernotes";
    //p2="icomputernotes" will generate error
    cout<<p2<<endl;
    return 0;
}

Output of Example program for string and pointer in C C++

Example program for string and pointer in C C++

Other important string programs in C C++

  1. String input-output without space
  2. String input-output with space
  3. Strlwr() function example program
  4. Strupr() function example program
  5. Strlen() function example program
  6. Strrev() function example program
  7. Strcpy() function example program
  8. Strcat() function example program
  9. Strcmp() function example program
Share it to:

Pointer to structure example program in C C++

Pointer to structure example program in C C++

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

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

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

Pointer to structure example program in C

#include<stdio.h>

struct student
{
    char grade;
    int marks;
    float percent;
};

int main()
{
    struct student std;
    struct student *ptr;
    ptr=&std;
    printf("Enter Grade   : ");
    scanf("%c",&std.grade);
    printf("Enter Marks   : ");
    scanf("%d",&std.marks);
    printf("Enter Percent : ");
    scanf("%f",&std.percent);
    printf("The Grade is  : %c",ptr->grade);
    printf("\nThe Marks is  : %d",ptr->marks);
    printf("\nThe Percent is: %f",ptr->percent);
    return 0;
}

Pointer to structure example program in C++

#include<iostream>
using namespace std;

struct student
{
    char grade;
    int marks;
    float percent;
};

int main()
{
    struct student std;
    struct student *ptr;
    ptr=&std;
    cout<<"Enter Grade    : ";
    cin>>std.grade;
    cout<<"Enter Marks    : ";
    cin>>std.marks;
    cout<<"Enter Percent  : ";
    cin>>std.percent;
    cout<<"The Grade is   : "<<ptr->grade<<endl;
    cout<<"The Marks is   : "<<ptr->marks<<endl;
    cout<<"The Percent is : "<<ptr->percent<<endl;
    return 0;
}

Output of Pointer to structure example program in C C++

Pointer to structure example program in C C++

Related structure example programs in C C++

  1. Declaration and initialization of structure
  2. Array of structure
Share it to:

Pointer to array example program in C C++

Pointer to array example program in C C++

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

Pointer to array क्या होता है जानने के लिए देखें—Pointer to array in C

C Language में Pointer to Pointer क्या होता है जानने के लिए देखें— Pointer to pointer in C

Pointer to array example program in C

#include<stdio.h>
int main()
{
    int arr[5]={3,9,1,4,8},i;
    int *ptr;
    ptr=&arr[0];
    for(i=0;i<5;i++)
    {
        printf("Element = %d Address = %u\n",*ptr,ptr);
        ptr++;
    }
    return 0;
}

Pointer to array example program in C++

#include<iostream>
using namespace std;
int main()
{
    int arr[5]={3,9,1,4,8},i;
    int *ptr;
    ptr=&arr[0];
    for(i=0;i<5;i++)
    {
        cout<<"Element = "<<*ptr<<"Address = "<<ptr<<endl;
        ptr++;
    }
    return 0;
}

Output of Pointer to array example program in C C++

Pointer to array example program in C C++

More example programs of array in C C++

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Largest Element in Array
  5. Smallest element in Array
  6. Reverse Elements of Array
  7. Merging two arrays
  8. Searching in array (Linear search)
  9. Sorting in array (Selection sort)
Share it to:

Pointer arithmetic example programs in C C++

Pointer arithmetic example programs in C C++

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

C Language में Pointer to Pointer क्या होता है जानने के लिए देखें— Pointer to pointer in C

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

Incrementing pointer in C example program

#include<stdio.h>
int main()
{
    int num, *ptr;
    ptr=#
    printf("value of ptr = %u\n",ptr);
    ptr=ptr+1;
    printf("value of ptr = %u\n",ptr);
    ptr=ptr+1;
    printf("value of ptr = %u\n",ptr);
    return 0;
}

Incrementing pointer in C++ example program

#include<iostream>
using namespace std;
int main()
{
    int num, *ptr;
    ptr=#
    cout<<"value of ptr = "<<ptr<<endl;
    ptr=ptr+1;
    cout<<"value of ptr = "<<ptr<<endl;
    ptr=ptr+1;
    cout<<"value of ptr = "<<ptr<<endl;
    return 0;
}

Output of incrementing pointer in C C++ example program

Pointer Arithmetic Incrementing Programs in C C++

Decrementing pointer in C example program

#include<stdio.h>
int main()
{
    int num, *ptr;
    ptr=#
    printf("value of ptr = %u\n",ptr);
    ptr=ptr-1;
    printf("value of ptr = %u\n",ptr);
    ptr=ptr-1;
    printf("value of ptr = %u\n",ptr);
    return 0;
}

Decrementing pointer in C++ example program

#include<iostream>
using namespace std;
int main()
{
    int num, *ptr;
    ptr=#
    cout<<"value of ptr = "<<ptr<<endl;
    ptr=ptr-1;
    cout<<"value of ptr = "<<ptr<<endl;
    ptr=ptr-1;
    cout<<"value of ptr = "<<ptr<<endl;
    return 0;
}

Output of decrementing pointer in C C++ example program

Pointer Arithmetic Decrementing Programs in C C++

Related pointer programs in C C++

  1. Declaration and assignment of pointer
  2. Pointer to pointer
  3. Sum of two numbers using pointer
  4. Average of three numbers using pointer
  5. Swapping two variables using pointer
Share it to:

C C++ program to swap values of two variable using pointer

C C++ program to swap values of two variable using pointer

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

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

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

C program to swap values of two variable using pointer

#include<stdio.h>
int main()
{
    int n1,n2,*p1,*p2,temp;
    printf("Enter number1: ");
    scanf("%d",&n1);
    printf("Enter number2: ");
    scanf("%d",&n2);
    p1=&n1;
    p2=&n2;
    temp=*p1;
    *p1=*p2;
    *p2=temp;
    printf("Number1 = %d\n",n1);
    printf("Number2 = %d\n",n2);
    return 0;
}

C++ program to swap values of two variable using pointer

#include<iostream>
using namespace std;
int main()
{
    int n1,n2,*p1,*p2,temp;
    cout<<"Enter number1: ";
    cin>>n1;
    cout<<"Enter number2: ";
    cin>>n2;
    p1=&n1;
    p2=&n2;
    temp=*p1;
    *p1=*p2;
    *p2=temp;
    cout<<"Number1 = "<<n1<<endl;
    cout<<"Number2 = "<<n2<<endl;
    return 0;
}

Output of C C++ program to swap values of two variable using pointer

C C++ program to swap values of two variable using pointer

List of important pointer example programs in C C++

  1. Declaration and assignment of pointer
  2. Pointer to pointer
  3. Sum of two numbers using pointer
  4. Average of three numbers using pointer
  5. Pointer Arithmetic
Share it to:

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

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

C Language की विशेषताओं एवं शक्तियों को जानने के लिए देखें—Features and Powers of C

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

Object Oriented Programming (OOP) की विभिन्न अवधारणाओं को जानने के लिए देखें—Concepts of OOP

C program to find average of three numbers using pointer

#include<stdio.h>
int main()
{
    int n1,n2,n3,*p1,*p2,*p3;
    float avg;
    printf("Enter three numbers: ");
    scanf("%d%d%d",&n1,&n2,&n3);
    p1=&n1;
    p2=&n2;
    p3=&n3;
    avg=(*p1+*p2+*p3)/3.0;
    printf("Average = %f",avg);
    return 0;
}

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

#include<iostream>
using namespace std;
int main()
{
    int n1,n2,n3,*p1,*p2,*p3;
    float avg;
    cout<<"Enter three numbers: ";
    cin>>n1>>n2>>n3;
    p1=&n1;
    p2=&n2;
    p3=&n3;
    avg=(*p1+*p2+*p3)/3.0;
    cout<<"Average = "<<avg;
    return 0;
}

Output C C++ program to find average of three numbers using pointer

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

Useful pointer programs in C C++

  1. Declaration and assignment of pointer
  2. Pointer to pointer
  3. Sum of two numbers using pointer
  4. Swapping two variables using pointer
  5. Pointer Arithmetic
Share it to:

C C++ program to find sum of two numbers using pointer

C C++ program to find sum of two numbers using pointer

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

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

C-Language में Operator Precedence और Associativity Rule क्या होता है जानने के लिए देखें— Precedence and Associativity in C

C program to find sum of two numbers using pointer

#include<stdio.h>
int main()
{
    int n1,n2,*p1,*p2,sum;
    printf("Enter two numbers: ");
    scanf("%d%d",&n1,&n2);
    p1=&n1;
    p2=&n2;
    sum=*p1+*p2;
    printf("Sum = %d",sum);
    return 0;
}

C++ program to find sum of two numbers using pointer

#include<iostream>
using namespace std;
int main()
{
    int n1,n2,*p1,*p2,sum;
    cout<<"Enter two numbers: ";
    cin>>n1>>n2;
    p1=&n1;
    p2=&n2;
    sum=*p1+*p2;
    cout<<"Sum = "<<sum;
    return 0;
}

Output of C C++ program to find sum of two numbers using pointer

C C++ program to find sum of two numbers using pointer

Important pointer programs in C C++

  1. Declaration and assignment of pointer
  2. Pointer to pointer
  3. Average of three numbers using pointer
  4. Swapping two variables using pointer
  5. Pointer Arithmetic
Share it to:

Example program for pointer to pointer in C C++

Example program for pointer to pointer in C C++

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

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

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

Example program for pointer to pointer in C

#include<stdio.h>
int main()
{
    int num=5;
    int *ptr1;
    ptr1=#
    int **ptr2;
    ptr2=&ptr1;
    printf("Value of num   = %d",num);
    printf("\nAddress of num = %p",&num);
    printf("\nValue of num   = %d",*ptr1);
    printf("\nAddress of num = %p",ptr1);
    printf("\nValue of num   = %d",**ptr2);
    printf("\nAddress of num = %p",*ptr2);
    return 0;
}

Example program for pointer to pointer in C++

#include<iostream>
using namespace std;
int main()
{
    int num=5;
    int *ptr1;
    ptr1=#
    int **ptr2;
    ptr2=&ptr1;
    cout<<"Value of num   = "<<num<<endl;
    cout<<"Address of num = "<<&num<<endl;
    cout<<"Value of num   = "<<*ptr1<<endl;
    cout<<"Address of num = "<<ptr1<<endl;
    cout<<"Value of num   = "<<**ptr2<<endl;
    cout<<"Address of num = "<<*ptr2<<endl;
    return 0;
}

Output of example program for pointer to pointer in C C++

Pointer to pointer program output in C CPP

Similar pointer example programs in C C++

  1. Declaration and assignment of pointer
  2. Sum of two numbers using pointer
  3. Average of three numbers using pointer
  4. Swapping two variables using pointer
  5. Pointer Arithmetic
Share it to:

Example program for pointer in C C++

Example program for pointer in C C++

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

C Language में Pointer to Pointer क्या होता है जानने के लिए देखें— Pointer to pointer in C

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

Example program for pointer in C

#include<stdio.h>
int main()
{
    int num=5;
    int *ptr;
    ptr=#
    printf("Value of num   = %d",num);
    printf("\nAddress of num = %p",&num);
    printf("\nValue of ptr   = %p",ptr);
    printf("\nAddress of ptr = %p",&ptr);
    printf("\nValue of num   = %d",*(&num));
    printf("\nValue of num   = %d",*ptr);
    return 0;
}

Example program for pointer in C++

#include<iostream>
using namespace std;
int main()
{
    int num=5;
    int *ptr;
    ptr=#
    cout<<"Value of num   = "<<num<<endl;
    cout<<"Address of num = "<<&num<<endl;
    cout<<"Value of ptr   = "<<ptr<<endl;
    cout<<"Address of ptr = "<<&ptr<<endl;
    cout<<"Value of num   = "<<*(&num)<<endl;
    cout<<"Value of num   = "<<*ptr<<endl;
    return 0;
}

Output of Example program for pointer in C C++

Pointer program output in C CPP

Related pointer programs in C C++

  1. Pointer to pointer
  2. Sum of two numbers using pointer
  3. Average of three numbers using pointer
  4. Swapping two variables using pointer
  5. Pointer Arithmetic
Share it to: