0

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;
}

Edited by vineeshvs: n/a

1
Contributor
1
Reply
4
Views
6 Years
Discussion Span
Last Post by vineeshvs
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.