top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why pointer passing can not be called called by reference in C?

+3 votes
490 views

Called by reference is a mechanism where we can bring the changes to a variable done in the called function to calling function which can be done via passing pointers in C. But most of the books are referring that C does not support pass by reference method.

Can someone explain why?

posted Nov 17, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
C is a procedural language and C++ is an object oriented programming. Procedural language supports the concept of function whereas Object oriented programming supports the concept of methods.

2 Answers

+1 vote

In C everything is pass by the value even if you pass the pointer or double pointer or triple pointer you pass the value and somehow manage the change of value of variable by accessing the location using the pointer value you have received. So in C we call everything is pass by value.

While in C++ you can pass the reference.

answer Dec 9, 2014 by Salil Agrawal
0 votes

Pointer is used to store the address of variable.
So, you are not passing the address of pointer you are just pasing the value of pointer (address of OTHER variable).

Ex:

int *p,a=10;
p = &a;
function_name(p);

So, here you are not passing the address. So, It is not called called by reference.

Now.. If you pass the address of pointer to the function.
Then, In function body (function prototype) you have to catch it through double pointer and now it will be called as call by reference.
Ex:

 main()
  {       
    int *p,a=10;
    p = &a;
    function_name(&p);
  }

 void function_name(int **q)
 {
 }
answer Dec 9, 2014 by Chirag Gangdev
...