1. Find as many issues as possible
and correct them
char *GenerateRandomString(void)
{
int i;
char RandomString[10];
for(i = 0; i <= 10; i++)
{
RandomString[i] = rand() % 256;
}
return RandomString;
}
2. Find as many issues as possible
and correct them
malloc(n) allocates n bytes in the heap.
int main(void)
{
int *ptr = (int *) malloc(10);
for(int i =0; i <10; i++)
{
*ptr++ = i;
}
free(ptr);
}
3. What is wrong with this code?
#define SQUARE(x) x*x
4. Explain the following function.
void dsp_func(
DSPfract *ip,
DSPshort io,
DSPfract *op,
DSPshort oo,
DSPfract *vp,
DSPfract *cp,
DSPshort m,
DSPshort n)
{
DSPfract *s, a;
int i, j;
s = op;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
a = -(*vp++) * (*cp++) * 2;
a -= (*vp++) * (*cp++);
a += (*ip) * (*cp++);
a += (*vp++) * (*cp++) * 2;
a += (*vp) * (*cp++);
*vp = *(vp - 1);
varptr--;
*vp-- = *ip;
*op = a;
*vp = *(vp - 1);
vp--;
*vp = *op;
ip += io;
op += oo;
cp -= 5;
}
op = s;
ip = op;
io = oo;
cp += 5;
vp += 4;
}
}