C Program to print address of character using pointer

Simple C program to print address of character using pointer: We know, pointer store the address of another variables like integer variables, character variables. Here we want to print address of character so first we declare a pointer to character and then store the address of character into it. We can also print address using & and to print address, we use %u.
 
/* C Program to print address of character */
#include<stdio.h>
int main()
{
 char ch,*ptr;
 printf("Enter a character: ");
 scanf("%c",&ch);
 ptr=&ch;
 printf("Address = %u\n",ptr);
 return 0;
}
/* End of the program */
 
Another C program to print address of character using pointer
 
/* C Program to print address of character */
#include<stdio.h>
int main()
{
 char ch,*ptr;
 printf("Enter a character: ");
 scanf("%c",&ch);
 ptr=&ch;
 printf("Address = %u\n",ptr);
 printf("Address = %u\n",&ch);
 return 0;
}
/* End of the program */
 


Popular posts from this blog