Learn How to Program in C

by
Dr. Kristin Switala

Introduction

Directives

Variables

Conditionals

Loops

Arrays

Pointers

Strings

Functions

Structures


Site Map

Review: Pointers (c)

Instructions: Think about each question and write the answer in your notebook.


General Questions

1. What does a pointer contain?

2. How do we declare a pointer?

3. What does 'dereferencing a pointer' mean?


White Box Testing

1. Fix the errors in this C source code. There are 2 errors.

#include<stdio.h>
void main( )
{
int shoes = 3456;
int point = NULL;
point = shoes;
printf("\nThe warehouse contains %d shoes.", shoes);
printf("\nThe computer stores this variable at address %p.", point);
}

2. Fix the errors in this C source code. There are 2 errors.

#include<stdio.h>
void main( )
{
int num = 9876;
int *point = NULL;
point = #
printf("\n%p\tNumber's Value \t%p\tPointer's Value", num, point);
printf("\n%p\tNumber's Address\t%p\tPointer's Address", &num, point);
printf("\n\nNotice that the Number's Address is the same as the Pointer's Value.");
}

3. Fix the errors in this C source code. There are 2 errors.

#include<stdio.h>
void main( )
{
long zip = 94003;
int *point = NULL;
point = &zip;
printf("\nSara's zip code is %ld.", zip);
printf("\nThe computer stores Sara's zip code at %p.", point);
++zip;
++pont;
printf("\nPablo's zip code is %ld.", zip);
printf("\nThe computer stores Pablo's zip code at %p.", point);
}

4. Fix the errors in this C source code. There are 2 errors.

#include<stdio.h>
void main( )
{
long eggs = 130560;
long *point = NULL;
printf("\nKetchum's Poultry Farm produces %ld eggs per week.", eggs);
point = &eggs;
point = eggs * 4;
printf("\nThat's %ld eggs per month.", point);
}

Copyright
© 2001
Kristin Switala
Hosted by www.Geocities.ws

1