- DP -
2009-05-12 08:47:16 UTC
[a.] From the declared size of the array which contains it.
[b.] By a length byte stored at the beginning of the string.
[c.] By a null terminator stored at the end of the string.
[d.] By a length byte stored at the end of the string.
My thoughts: I think this one is C because the null terminator determines where the string ends?
2. Given the following declaration,
char string[8] = "abcdefg"; what is output by the following statement: printf ("%s\n", string + 3);
[a.] abcdefg
[b.] abc
[c.] defg
[d.] cdefg
My thoughts: I think this one is C because the string was shifted 3, but I'm not sure.
3. The following code char string[8] = "abcdefg"; *string = '\0'; printf ("%s", string);
[a.] generates a compiler error
[b.] generates a run-time error
[c.] creates no output, but no error is generated
[d.] creates the output bcdefg
My thoughts: I think this one is C because the string's first location is changed to a null terminator, therefore the string is empty now?
4. Let p be a pointer to an integer and num be an integer variable. Which of the following is NOT a correct assignment ?
[a.] p = 0;
[b.] p = 5;
[c.] p = p + 7;
[d.] p = #
My thoughts: I'm not sure about this one. They all seem valid to me.
5. Let p be a pointer to an integer and let n be an int variable. Then after the assignment p = &n;
the value of *p is
[a.] the address of the pointer p
[b.] the value stored in the variable n
[c.] the address of the variable n
[d.] none of the above
My thoughts: I think it would be b because the *p is the dereference of the address, so it would actually be the value?
6. The arrow operator, ->, has the effect of which other two operators ?
[a.] * and ++ (dereference and then increment pointer)
[b.] - and > (decrement and then check for greater-than
[c.] [] and . (get array element and then get member)
[d.] * and . (dereference and then get member)
My thoughts: I think the answer is d, but I'm not 100% sure.
7. The expression sizeof(struct foo) refers to
[a.] the number of member variables in struct foo
[b.] the size of the largest member variable in struct foo
[c.] the total size of struct foo in bytes
[d.] the number of pointer members in struct foo
My thoughts: I'm actually not sure. I think it's C, but I'm not confident in my answer.
8. # What is the effect of dereferencing a pointer which has the value NULL ?
[a.] Zero is returned.
[b.] The operation is ignored.
[c.] The compiler detects the error and issues an error message.
[d.] A run-time error results.
My thoughts: I think the answer would be D because the NULL makes the program give an error?
Please answer and explain!
Thank you!