M
Mahendra
I have following code snippet -
int *createIncidenceMatrix(int numEdges, int numVertices) {
int *p = (int *) calloc((numEdges*numVertices), sizeof(int));
if(p == NULL) {
printf("Could not allocate memory");
exit(0);
}
return p;
}
void createIncidencePerView(int numEdges, int numVertices, int viewId) {
int *pnew = createIncidenceMatrix(numEdges, numVertices);
}
This code compiles fine. I am trying to understand if this will run as
intended. Obviously, I tried running the code also. My question is -
When createIncidenceMatrix() return p which is local variable, will p
get deallocated at return call ?
So when i make createIncidenceMatrix() call inside
createIncidencePerView(), will the call createIncidenceMatrix() tries to
assign deallocated local pointer to the pnew pointer ?
Thanks
Mahendra
int *createIncidenceMatrix(int numEdges, int numVertices) {
int *p = (int *) calloc((numEdges*numVertices), sizeof(int));
if(p == NULL) {
printf("Could not allocate memory");
exit(0);
}
return p;
}
void createIncidencePerView(int numEdges, int numVertices, int viewId) {
int *pnew = createIncidenceMatrix(numEdges, numVertices);
}
This code compiles fine. I am trying to understand if this will run as
intended. Obviously, I tried running the code also. My question is -
When createIncidenceMatrix() return p which is local variable, will p
get deallocated at return call ?
So when i make createIncidenceMatrix() call inside
createIncidencePerView(), will the call createIncidenceMatrix() tries to
assign deallocated local pointer to the pnew pointer ?
Thanks
Mahendra