Thread: Vector

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    36

    Vector

    hey all i came across this term while learning about vectors:
    "Bounds checking"

    what does that mean?

    there is a line in the tutorial that says:

    Unfortunately, the [] operator still does not provide bounds checking. There is an alternative way of accessing the vector, using the function at, which does provide bounds checking at an additional cost.
    kindly help...

  2. #2
    Registered User
    Join Date
    Jun 2012
    Location
    Here
    Posts
    23
    Imagine something like this:

    Code:
    int num_list[5] = {1, 5, 77, 3, 35}; // has only 5 elements
    
    cout << num_list[6] << endl; // but 6-th element is also accessible
    cout << num_list[-7] << endl; // You can do this too
    Bounds checking means that in 5-item array only elements from 0 to 4 are accessible.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    If a function has bounds checking it means that the argument you passed in is checked against the bounds of the data structure, to make sure it is a valid argument, before using it to access the data structure.
    Last edited by whiteflags; 12-15-2012 at 08:10 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector<vector<int> > access element.
    By nimitzhunter in forum C++ Programming
    Replies: 0
    Last Post: 01-23-2011, 05:14 AM
  2. Converting string vector to integer vector
    By CPlus in forum C++ Programming
    Replies: 4
    Last Post: 05-08-2010, 05:43 AM
  3. Storing a vector inside a vector
    By csonx_p in forum C++ Programming
    Replies: 1
    Last Post: 09-14-2008, 05:15 AM
  4. Simple Question memset(vector<int>, 0, sizeof(vector<int>))
    By HyperShadow in forum C++ Programming
    Replies: 6
    Last Post: 12-10-2007, 04:56 PM
  5. vector of pointers vs vector of values
    By Shadow12345 in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2002, 02:27 PM