You are on page 1of 3

Lab 6

This manual covers:


Addresses and pointers Passing Arguments to Functions by Reference Pointer Expressions and Pointer Arithmetic.

Exercise 6.1 Write and compile the following program. // array name is the same as the address of the array's first element #include <stdio.h> int main (void) { char array[5]; printf("array = %p\n&array[0] = %p\n&array = %p\n", array,&array[0],&array); return 0; }

Exercise 6.2 Write the following program. Compile, link and run it. (Pointer as a function argument) #include<stdio.h> void my_switch(int *a,int *b); int main() { int a=2,b=5; my_switch(&a,&b); printf("New a=%d and new b=%d\n",a,b); //function prototype

return 0; } void my_switch(int *a,int *b) { int temp; temp=*a; *a=*b; *b=temp; return; } Exercise 6.3 Write the following program. Compile, link and run it. (Changing pointer data) #include<stdio.h> int main() { int anInt=5; int *anIntPointer=&anInt; printf("%d\n",*anIntPointer); *anIntPointer=20; printf("%d\n",*anIntPointer); printf("%d\n",anInt); printf("%X\n",anIntPointer); Hexadecimal return 0;} //print address of anInt in

LAB ASSIGNMENT 3 Write a program that reads in a two-dimensional array representing the coordinates of points in space. The program should determine the largest absolute value in the array and scale each element of the array by dividing it by this largest value. The new array, which is called the normalized array, should have the largest value. The program consists of two functions: main() obtains the number of data points, and the x, and y coordinates of each point. normalize() normalize the array.

You might also like