DEV Community

SushantDhiman2004
SushantDhiman2004

Posted on

C actually don't have Pass-By-Reference

Recently I decided to dive into low-level programming, and of course I started with revising pointers. I picked up the free e-book Extreme C by Kamran Amini and found an interesting example in it.

void func(int* a) {
int b = 10;
*a = 5;
a = &b;
}

Above function is:

  1. Receiving a pointer to variable “a”.
  2. Initializing a new variable “b”.
  3. Dereference pointer “a” and changing it’s value to 5.
  4. Finally replacing the address of “a” with “b”.

Read Complete Article

Top comments (0)