Professional Documents
Culture Documents
CIS 1101-Exercise On Pointers
CIS 1101-Exercise On Pointers
3) What is the difference between a character variable and a character pointer variable ?
4) What is the difference between an integer variable and an integer pointer variable ?
5) What does dereference or indirection mean? What is the symbol for dereference operator in C?
B. Run this program in any C compiler and answer the following questions below.
#include <stdio.h>
int main()
{
char x = 'A';
int y = 10;
char * xptr;
int * yptr;
printf("\nVariable x: size = %d, value = %-5c and address is %p", sizeof(x), x, &x);
printf("\nVariable y: size = %d, value = %-5d and address is %p", sizeof(y), y, &y);
/*** Assign the address of x and y to xptr and yptr respectively ***/
xptr = &x;
yptr = &y;
printf("\nVariable xptr: size = %d, value = %p and address is %p", sizeof(xptr), xptr, &xptr);
printf("\nVariable yptr: size = %d, value = %p and address is %p", sizeof(yptr), yptr, &yptr);
return 0;
}
1) Answer the question and complete the table below based on the program above and its output.
y
xptr
yptr
2) Represent each variable above (x, y, xptr and yptr) by a box, whose box size is proportional to the variable’s byte
size. That is, a 4-byte variable has a box size that is 4 times bigger than a 1-byte variable. Label each box with the
variable’s name, value and beginning address. If the variable’s value is an address of another variable, draw an
arrow from the box’s value to the other box that has that address.
C. Determine the symbols of the operators used in each of the following and give a sample C statement using the
operator.
1. Write the declaration of the following variables. Write the answers on the space provided for.
a) X and Y - as pointers to an integer variable
b) Z – as an integer variable
2. Using the declaration in #1, write the ONE (1) C statement on the space that will accomplish each of the following:
a) Let X point to Z.
b) Using X, let Y point to Z.
c) Input from the keyboard the value of Z.
d) Using X, display on screen the value of Z.
e) Using Y, change the value of Z to 100.
f) Display on screen the address of Z in hexadecimal form.
g) Display on screen the value of Y in hexadecimal form.