CS 23 Software Design and Implementation

X-Hour Quiz

Pesky Pointers Quiz

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 very pesky pointers quiz. We went over this in x-hour. 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!

Slippery Strings

This set of problems ask you to guess the execution results of C code. In this exercise, you will understand how C handle strings and how to write correct string processing code. Assume that:

 char* p = "ABCDE"; 

for all questions.

Following string questions are not mentioned today, but they are also important.

1 Array!

We have the following intialization

int a[3]; a[0]=0; a[1]=1; a[2]=2;  
int *b=a;  
short *c=a;

for all questions in this section.

2 Double Array!

We have the following initialization

int B[2][2];  
B[0][0]=1;  
B[0][1]=2;  
B[1][0]=3;  
B[1][1]=4;

for all questions in this section.

When you want to declare a array and initialize it at the same time, the right way is to do as follows:

int D[2][2] = {{1, 2}, {3, 4}};

or:

int D[] = {1, 2, 3, 4};

Following string questions are not mentioned today, but they are also important.

3 Pointer of a Pointer

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:

int a = 12;  
int b = &a;  
int **c = &b;

The following questions are also important, but they are not mentioned in class.