Identify syntax, runtime, and logic errors t. Structs and Arrays (4 points) Belo
ID: 3855923 • Letter: I
Question
Identify syntax, runtime, and logic errors
Explanation / Answer
1) struct strArray arr;
This line contains a syntax error . You should have strArr instead of strArray as strArr is the name of the structure.
2) char [256] temp;
This contains a syntax error too. Instead of using the square brackets before the array object variable, we have to use it after.
char temp[256];
3) if (temp=="stop").
This contains a logical error. Strings in C cannot be compared using the equality operator. Use of strcmp() is appreciated.
4)arr.array=(char **)realloc(arr.size*sizeof(char));
This contains a runtime error. invalid conversion from 'unsigned int' to 'void*' [-fpermissive]|. This type of conversion in c is not allowed.
5) arr.array=(char **)realloc(arr.size*sizeof(char));
This aslo contains a Syntax Error . The definition of realloc() function says that it should have two arguments.Prototype definition of realloc().
void *realloc(void *ptr, size_t size);
So it also needs the argument that states what entity is being reallocated.
void *realloc(void *ptr, size_t size);
So it also needs the argument that states what entity is being reallocated.