TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Friday, 15 May 2020

Pointer In C | Pointer In C In Hindi | Pointer In C Example | What Is Pointer In C

 Pointer In C  


The pointer in C language is a variable which stores the address of another variable. This variable can be of type int, char, array, function, or any other pointer. The size of the pointer depends on the architecture. However, in 32-bit architecture the size of a pointer is 2 byte.

image of pointer in c
Fig: Pointer in C

Example

     

      int n = 10;   

      int* p = &n;


Advantage of pointer


1) Pointer reduces the code and improves the performance, it is used to retrieving strings, trees, etc. and used with arrays, structures, and functions.

2) We can return multiple values from a function using the pointer.

3) It makes you able to access any memory location in the computer's memory.


Usage of pointer


There are many applications of pointers in c language.


1) Dynamic memory allocation

In c language, we can dynamically allocate memory using malloc() and calloc() functions where the pointer is used.


2) Arrays, Functions, and Structures

Pointers in c language are widely used in arrays, functions, and structures. It reduces the code and improves the performance.


Declaring a pointer


The pointer in c language can be declared using * (asterisk symbol). It is also known as indirection pointer used to dereference a pointer.

       int *a;//pointer to int  

      char *c;//pointer to char     


  Program


      #include<stdio.h>  

 

    int main(){  

 

    int number=50;    

 

    int *p;      

     

      p=&number;//stores the address of number variable    

    

    printf("Address of p variable is %x \n",p); 

 


     printf("Value of p variable is %d \n",*p); 

 

      return 0;   

                     

       }              


Output


Address of number variable is fff4

Address of p variable is fff4

Value of p variable is 50

 

Pointer to array

 

     int arr[10];  

     int *p[10]=&arr; 

 

Pointer to a function

 

    void show (int);  

   void(*p)(int) = &display; 

 

Pointer to structure

     

     struct st {  

    int i;  

    float f;  

    }ref;  

     struct st *p = &ref;  

 

NULL Pointer


A pointer that is not assigned any value but NULL is known as the NULL pointer. If you don't have any address to be specified in the pointer at the time of declaration, you can assign NULL value. It will provide a better approach.


Example:


int *p=NULL;


No comments:

Post a Comment