Lab 8

Part 1
Pointers in C are variables that store an address. In this part, you need to check the size of a C pointer. Create a C file named "lab8_part1.c", declare the following pointers:

int a = 23;
int *p1 = &a;

int b[] = {0};
int *p2 = b;

char c = 'A';
char *p3 = &c;

double d = 10.0;
double *p4 = &d;

Then check the size of them (using the sizeof() function) and print the output in your script. What is the output? What does the output mean? Give a brief explanation of the output. (Create a file and use "cat" to display your answer.)

Part 2
Create a C file named "lab8_part2.c", type in the following program:

int arr[5] = {1,2,3,4,5};
char brr[5] = {1,2,3,4,5};
int *p1 = arr;
char *p2 = brr;

printf("%p\n", p1);
printf("%p\n", p1+1);

printf("%p\n", p2);
printf("%p\n", p2+1);

What is the output? What does the output mean? Give a brief explanation of the output. (Create a file and use "cat" to display your answer.)

Part 3
Create a C file named "lab8_part3.c". Write a program that reverses an array using pointers (you cannot use another array to do this, have your elements switch places). For example, if the input array is {1,2,3,4,5,6} after reversing it should be {6,5,4,3,2,1}.

Have your program prompt the user to enter the length of the array, then type in elements (have at least two attempts: one with the odd length and one with even length). Also use "cat" to display your program and include that in your log file.

Any answers to questions can appear as in the output, i.e.
printf("I observe ....");
or you can type your answers into files and use "cat" to show them. Have a different program for each part, even though there might be code copied from one to another. Don't forget to add the appropriate "include" statements at the top of the programs.