I im dynamically allocating an array, like this ...
I'm dynamically allocating an array, like this:
int *iarray = (int *)malloc(nints);
malloc isn't returning NULL, but the code isn't working.
A:malloc is a low-level, typeless allocator. It doesn't know how you're going to use the memory; all it does is to allocate as many bytes of memory as you ask it. Therefore (except when you're allocating arrays of char) you must multiply by the size of the elements in the array you're allocating:
int *iarray = malloc(nints * sizeof(int));
int *iarray = malloc(nints * sizeof(*iarray));
(The latter fragment can be more reliable if the type of iarray might change, since there's only one place to change it. Also, the casts have been removed;
2016-04-06, 1095👍, 0💬
What will be printed as the result of the operation below: #define swap(a,b) a=a+b;b=a-b;a=a-b; void...
Where are all .NET Collection classes located ? System.Collection namespace has all the collection c...
How To Compile a JUnit Test Class? Compiling a JUnit test class is like compiling any other Java cla...
The following variable is available in file1.c, who can access it? static int average; Answer: all t...
Write an equivalent expression for x%8? x&7