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:

Published by

admin

I am a computer teacher, programmer and web developer