Vector

This is a discussion on Vector within the C++ Programming forums, part of the General Programming Boards category; hey all i came across this term while learning about vectors: "Bounds checking" what does that mean? there is a ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    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 07: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, 04: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, 03:56 PM
  5. vector of pointers vs vector of values
    By Shadow12345 in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21