CS 50: Software Design and Implementation

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 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)!

Slippery Strings

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:

 char* p = "HELLO"; 

for all questions.

1 Array!

We have the following intialization

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

for all questions in this section.

2 Double Array!

We have the following initialization

int B[2][2];  

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}};


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

Following exact string questions were not mentioned today, but similar questions were talked about.

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;