Pointers are typically the one thing people coming from Javaland struggle with when encountering C for the first time. If you come bottom up from assemblerland you are OK.
Here is our pesky pointers quiz. You will get a marked up copy of your answer sheet back. We will grade it but it will have zero impact on your course grade. This is purely fun (in a torturous sense of course)!
This set of problems asks you to guess the execution results of C code. In this exercise, you will understand how C handles strings and how to write correct string processing code. Assume that:
for all questions.
Answer: Print p: HELLO
Answer: Print p[1]: E
Answer: Print *p+2: J
Answer: Print p: (STRANGE RANDOM CHARACTERS)
Answer: Print (p+1): ELLO
We have the following intialization
for all questions in this section.
Answer: A memory address, let’s just say x
Answer: 3
Answer: 6
Answer: Undefined, possibly Segmentation fault
Answer: 4
Answer: 9
Answer: 3, first half of a[0] is casted into a short int
We have the following initialization
for all questions in this section.
Answer: x (A memory address, let’s say it is x)
Answer: x
Answer: (x + 8)
Answer: 1
Answer: No. Compiling Error.
Answer: No. Compiling Error.
Answer: Yep.
When you want to declare a array and initialize it at the same time, the right way is to do as follows:
or:
Answer: No. Compiling Error.
Following exact string questions were not mentioned today, but similar questions were talked about.
Answer: x + 8
Answer: 3
This set of questions ask you to think about the value and equivalent expressions of an expression. You will need the similar skill in Lab 4.Suppose:
Answer: a, 12
Answer: b, &a
Answer:a, 12