Diagnostic Quiz
Problems
6. Pointer Usage
Remember the pointer type match we have discussed in the lecture. See Type Match.
A pointer to
<type>can only store the address of the variable with the same<type>You cannot assign
doubleto alongvariable, this will generate compilation error!
13. Memory Leak
free a "heap-object" pointer twice will cause undefined behavior or memory error
after freeing a "heap-object" pointer, if you access the address pointed to by the pointer, you will get memory error.
15. Valid String Declaration
In C, only the characters enclosed by "" will be considered as a valid string.
// Valid
char *s = "I am the real C string."
// Invalid
char *s = """
I am a C string.
"""
char *s = 'I am a string too!'
char s[] = { 's', 't', 'r', 'i', 'n', 'g' };Last updated