Pointers in C

Pointers in C

The pointer is a variable that stores the address of another variable.

These variables can be of any type such as int, char, array, function, or any other pointer.

Pointer Syntax

        
int *ptr;       //Pointer to integer  
char *ch;       //Pointer to character          
        
    

Here we declared a pointer ptr of int type and a pointer ch of char type.

Example of a pointer that stores the address of an integer

        
int num = 10;            
int *ptr = #            
        
    

Program

        
#include <stdio.h>

int main()
{
    int num = 50;
    int *ptr;
    ptr = &num;    //stores the address of number variable
    printf("Address of ptr variable is %x \n", ptr);
    printf("Value of ptr variable is %d", *ptr);
    return 0;
}            
        
    

Output

        
Address of ptr variable is dde2c53c 
Value of ptr variable is 50           
        
    



Join Our Social Media Connections

Post a Comment

0 Comments