Tuesday, May 19, 2009

You have a program containing the following statements:

#define ARRAYSIZE 20
char str[ARRAYSIZE]="Test string";
strcat(str, 'z');

When you run the program, it produces a segmentation fault.

Referring to the above scenario, how do you resolve the problem?
Choice a : Use malloc to dynamically allocate memory, rather than using a fixed array.
Choice b : Change 'z' to 'z\0'
Choice c : Change ARRAYSIZE to 21.
Choice d : Change 'z' to "z"
Choice e : Change strcat to strncat and specify a size of 1.

No comments: