0% found this document useful (0 votes)
146 views

Lab 6

This document covers exercises on pointers and addresses in C programming. It includes 3 exercises: 1) Demonstrating that the array name is the same as the address of the first element. 2) Passing arguments to a function by reference using pointers. 3) Changing the value of a variable by changing the value pointed to by a pointer. It also provides an assignment to write a program to normalize a 2D array by dividing each element by the largest absolute value.

Uploaded by

Firdaus Izz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
146 views

Lab 6

This document covers exercises on pointers and addresses in C programming. It includes 3 exercises: 1) Demonstrating that the array name is the same as the address of the first element. 2) Passing arguments to a function by reference using pointers. 3) Changing the value of a variable by changing the value pointed to by a pointer. It also provides an assignment to write a program to normalize a 2D array by dividing each element by the largest absolute value.

Uploaded by

Firdaus Izz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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