Solved programming problem

How to declare and print Pointer in C.

Source code

#include<stdio.h>

int main()

{

    int n;

    char m;

    int *ptr1; /// declaring a integer type pointer

    char *ptr2;/// declaring a character type pointer

    printf("Please Enter a number: ");

    scanf("%d",&n);

    printf("Please Enter a character: ");

    fflush(stdin);

    scanf("%c",&m);

    ptr1=&n; /// saving the address of n in pointer

    ptr2=&m; /// saving the address of m in pointer

    printf("The Number is: %d",*ptr1); ///printing the value of pointer

    printf("The character is: %c",*ptr2);

   

    return 0;

}

Output

Please Enter a number: 10
Please Enter a character: a

The Number is: 10
The character is: a

Join the discussion

Add your comment