Hello,
Thanks for reply...
I tried but not succeeded. Below is the code in which I tried to do thing in two ways (two functions), but no function did work....
Where am I doing mistake??
Code:
#include<stdio.h>
#include<stdlib.h>
// First test function
void test_alloc1(double *ptr)
{
double *ptr_local;
if((ptr_local=(double*)calloc(5, sizeof(double))) == NULL)
{
printf("\n\n Error");
return;
}
ptr=ptr_local;
int i;
double b=0.5;
for(i=0; i<=4; i++)
{
*(ptr+i)=b;
printf("\n In fun-1 @ %d value is %lf",(ptr+i),
*(ptr+i));
b=b+1.0;
}
return;
}
// Second test function
void test_alloc2(double **ptr)
{
if((*ptr=(double*)calloc(5, sizeof(double))) == NULL)
{
printf("\n\n Error");
return;
}
int i;
double b=0.5;
for(i=0; i<=4; i++)
{
**(ptr+i)=b;
printf("\n In fun-2 @ %d value is %lf",*(ptr+i),
**(ptr+i));
b=b+1.0;
}
return;
}
// Main
int main(void)
{
double *a;
int i;
// Calling first function
test_alloc1(a);
for(i=0; i<=4; i++)
printf("\n In MAIN-1 @ %d Value is : %lf",
(a+i),*(a+i));
free(a);
// Calling second function
test_alloc2(&a);
for(i=0; i<=4; i++)
printf("\n In MAIN-2 @ %d Value is : %lf",
(a+i),*(a+i));
return 0;
}
There is no compilation error (mingw with Code::blocks on windows).
Thanks and regards,
Amal.