i allocate memory for b_edge in function bark_edge and give value to only b_edge[1][1] and try to return b_edge from function. segmentation fault comes? can you please check why?

//function bark_edge+main program
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
double **bark_edge();
main()
{ 
  double **b_edge;
  b_edge=bark_edge(); 
  printf("%f",b_edge[1][1]);
}
//FUNCTION-bark_edge
double **bark_edge()
{
  int i=0;
  double **b_edge;
  //memory allocation for b_edge
  b_edge = (double**)malloc(10* sizeof(double *));
  if(b_edge== NULL)
    {
      printf("out of memory\n");
      return 0;
    }
  for(i = 0; i <1024 ; i++)
    {
      b_edge[i] = (double*)malloc(10 * sizeof(double));
      if(b_edge[i] == NULL)
  	{
  	  printf("out of memory\n");
  	  return 0;
  	}
    }
  b_edge[1][1]=2;
  return b_edge;
}

k it worked...
admins plz delete this thread. sry for inconvenience

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.