R
rahulsinner
Hi,
K&R states C as strictly pass by value while a numerous other no. of
books suggest both pass by value and pass by reference.
So there are a hell lot of people out there who argue in favour of
existence of pass by reference.
Consider the following:
#include <stdio.h> #include
<stdio.h>
#include <stdlib.h> void
swap(int *,int *);
int
main(void)
{
void foo(int *);
int i=10,j=20;
swap(&i,&,j);
int main(void)
return 0;
{ }
int *i=NULL;
foo(i);
void swap(int *ptr1,int *ptr2)
return 0; {
}
int temp=*ptr1;
*ptr1=20;
void foo(int *ptr)
*ptr2=10;
{
return;
ptr=(int *)malloc(sizeof *ptr); }
return;
}
The one on the right is often cited as the proof for "pass by value"
and the code on the right is the classical example of pass by
reference.
So,what should be the one's a[[roach when one is asked whether C is
pass by reference or not?
And if it is not,can anyone tell me a language which is?
K&R states C as strictly pass by value while a numerous other no. of
books suggest both pass by value and pass by reference.
So there are a hell lot of people out there who argue in favour of
existence of pass by reference.
Consider the following:
#include <stdio.h> #include
<stdio.h>
#include <stdlib.h> void
swap(int *,int *);
int
main(void)
{
void foo(int *);
int i=10,j=20;
swap(&i,&,j);
int main(void)
return 0;
{ }
int *i=NULL;
foo(i);
void swap(int *ptr1,int *ptr2)
return 0; {
}
int temp=*ptr1;
*ptr1=20;
void foo(int *ptr)
*ptr2=10;
{
return;
ptr=(int *)malloc(sizeof *ptr); }
return;
}
The one on the right is often cited as the proof for "pass by value"
and the code on the right is the classical example of pass by
reference.
So,what should be the one's a[[roach when one is asked whether C is
pass by reference or not?
And if it is not,can anyone tell me a language which is?