Forum: C Mar 10th, 2005 |
| Replies: 13 Views: 4,249 Hello,
You're welcome. If you have any further questions regarding the information I provided, don't hesitate to ask.
- Stack Overflow |
Forum: C Mar 10th, 2005 |
| Replies: 13 Views: 4,249 Hello,
Keep in mind if the space cannot be allocated, a null pointer is returned. If you try to write to the NULL block of memory, it will cause a segmentation fault. It's best to test for NULL... |
Forum: C Mar 10th, 2005 |
| Replies: 13 Views: 4,249 Hello,
In addition, you may find this short tutorial on Segmentation Faults handy: Locating a Segmentation Fault (http://cboard.cprogramming.com/showthread.php?t=59721#post421421)
Or if you... |
Forum: C Mar 10th, 2005 |
| Replies: 13 Views: 4,249 Hello,
Indeed it should. Each call to malloc will be subsequently freed during each loop iteration.
I'm not entirely sure. I don't have any hard evidence or facts at the moment, though I have... |
Forum: C Mar 10th, 2005 |
| Replies: 13 Views: 4,249 Hello,
If I am correct in my thinking, you will have lost allocated memory in your program. Your pointer, q, is a variable. Allocating memory to it 1000 times will cause a problem.
According... |
Forum: C Mar 9th, 2005 |
| Replies: 18 Views: 6,278 Hello,
1) What I mean't by function scope is simple. All it knows is what is happening within the function, and it doesn't have a clue as to what is happening in the 'int main' part of the... |
Forum: C Mar 9th, 2005 |
| Replies: 18 Views: 6,278 Hello,
No problem. Let me answer this question by example:#include <stdio.h>
#include <stdlib.h>
void test(char **p) {
/* run test; view memory address */
printf("Function scope:... |
Forum: C Mar 9th, 2005 |
| Replies: 18 Views: 6,278 Hello,
When you call free, the memory pointed to by the passed pointer is freed, but the value of the pointer in the caller remains unchanged, because C's pass-by-value semantics mean that called... |
Forum: C Mar 9th, 2005 |
| Replies: 18 Views: 6,278 Hello,
Also, be sure to set your variable to NULL after you free the memory. Example:free(G); /* Dynamically allocated memory is freed */
G = NULL; /* This ensures that we point our pointer to... |
Forum: C Mar 9th, 2005 |
| Replies: 18 Views: 6,278 Hello,
When free() is called, a block of memory previously allocated by a call to malloc, calloc or realloc is freed:Graph G=malloc(sizeof *G); /* Memory is dynamically allocated */
if (G !=... |