2012Week03Lecture3

15 pointers and arrays contd recall the array

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: to calculate and return the value of several variables together. •  One example of needing to return several values together is the vector opera1on of addi1on. 12 Passing by Reference Example •  Vectors may be specified by using a triple (x, y, z). •  In C, we can use an array to represent each vector: double v1[3] = {1, 2, 3}, v2[3] = {-1, 2, -3}, vr[3] = {0, 0, 0}; •  The prototype for a vector sum func1on: void v_sum(double v1, double v2, double vr); 13 Passing by Reference Example (cont’d) /* Function: v_sum * Purpose: Computes the sum of two vectors * Input: * v1 – array containing first vector * v2 – array containing second vector * Output: * vr – resultant vector of v1 + v2 */ void v_sum(double v1, double v2, double vr) { int i; // declare loop control variable for(i = 0; i < 3; i++) // loop 3...
View Full Document

Ask a homework question - tutors are online