What is Pointers in C.

By Shakib Ansari | Date: Thu, May 22, 2025

What is Pointer ?

Pointer ek variable hota hai jo kisi doosre variable ke address ko store karta hai. Normally, variables value store karte hain, par pointer variables memory address store karte hain.

Syntex

data_type *pointer_name;

Example

#include <stdio.h>

int main(int argc, char const *argv[])
{
    int a = 10;
    int *p;
    p = &a;

    printf("Value of a: %d\n", a);
    printf("Address of a: %p\n", &a);
    printf("Value of p (address of a): %p\n", p);
    printf("Value pointed by p: %d\n", *p);

    return 0;
}
Output:
Value of a: 10
Address of a: 0061FF18 (ye address aapke system ke hisaab se alag hoga)
Value of p (address of a): 0061FF18
Value pointed by p: 10


*p ka matlab hai "value at the address p is pointing to".

Call by Value vs Call by Reference

C language mein functions ko do tarike se call kiya ja sakta hai:

1. Call by Value (Value pass hoti hai)

  • Function ko variable ki copy milti hai.
  • Original variable change nahi hota.

Example:

#include <stdio.h>

void changeValue(int x) {
    x = 100;
}

int main() {
    int a = 10;
    changeValue(a);
    printf("Value of a: %d\n", a); // Output: 10
    return 0;
}
Yahaan a ki value change nahi hui kyunki function ko sirf copy mili thi.

2. Call by Reference (Address pass hota hai using pointers)

  • Function ko original variable ka address diya jata hai.
  • Function original variable ko directly modify karta hai.

Example:

#include <stdio.h>

void changeValue(int *x) {
  *x = 100;
}

int main() {
  int a = 10;
  changeValue(&a);
  printf("Value of a: %d\n", a); // Output: 100
  return 0;
}
Yahaan a ki value change ho gayi kyunki humne uska address pass kiya tha.

Use of Pointers in Real Projects

  • Dynamic memory allocation (malloc, calloc)
  • Function arguments for modifying values
  • Arrays and Strings
  • Linked lists, Trees, Graphs etc.

Conclusion

Pointers pe mastery banana C language ka ek core skill hai. Jab aap "Call by Reference" use karte ho, toh aapko pointers ka use aana chahiye. Dhyan rakho ki pointer use karte waqt memory address sahi ho warna program crash bhi ho sakta hai.

About the Author

Hi, I'm Shakib Ansari, Founder and CEO of BeyondMan. I'm a highly adaptive developer who quickly learns new programming languages and delivers innovative solutions with passion and precision.

Shakib Ansari
Programming

Comments