Pages

What is Pointer in C Language?

Pointer:

Pointers are special variables that store addresses rather than values. They are also known as pointer variables.


 How Do Pointers Work in C?

A variable that points to the location of another variable is called a pointer. It is stated with an asterisk (*) next to it. The declaration of a pointer uses the following syntax:


 datatype *var1


The following syntax is used to assign a variable's address to a pointer:


   datatype var1, *var2;


       var2=&var1;


A variable is accessible in two different ways.


1. Direct Access: The variable can be accessed directly using its name.


2. Indirect Access: You use a pointer for indirect access to that variable.


Example of Access Variables:

#include <stdio.h>

int main()

{

  int var = 5;

  printf("var: %d\n", var);



  printf("address of var: %p", &var);  

  return 0;

}



Working of Pointers:

Example:

#include <stdio.h>

#include <conio.h>

int main()

{

   int* pc, c;

    c = 22;

   printf("Address of c: %p\n", &c);

   printf("Value of c: %d\n\n", c);  // 22

    pc = &c;

   printf("Address of pointer pc: %p\n", pc);

   printf("Content of pointer pc: %d\n\n", *pc); //Output: 22

    c = 11;

   printf("Address of pointer pc: %p\n", pc);

   printf("Content of pointer pc: %d\n\n", *pc); //Output: 11

   *pc = 2;

   printf("Address of c: %p\n", &c);

   printf("Value of c: %d\n\n", c);   

//Output: 2

   return 0;

}


What Kinds of Pointers Are There?

There are primarily four different kinds of pointers:

1. Null Pointer

2. Void Pointer

3. Wild Pointer

4. Dangling Pointer


NOTE:-if You Want To More Updates On C Pointer Then Comment Down!!!!!!


**********************************

Happy to see you here๐Ÿ˜€๐Ÿ˜‡.

**********************************

visit www.javaoneworld.com for more posts.

*********************


No comments:

Post a Comment