Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

4.4. Vector data types

Vectors resemble arrays in that they contain multiple elements of the same type. But there are two important differences. First, a vector of a given type can only contain a specific number of elements. Second, when a vector is operated upon, every element is operated upon at the same time.

An example will make this distinction clear. Suppose you want to compute four sums of floating-point values. That is, a and b are arrays of four floats each, and you want c to hold the sums of the corresponding elements in a and b. You could try using code similar to the following:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint