Hi i started the book c++ from ground up,but looks like it's too old.I came across the bonded array.Question- what are they,where to use them,how and are they still used in c++11? Thank you .

As far as I know, the term "bounded array" is not really standard terminology for anything in particular. I would assume, however, that it refers to a static array, something like this: int arr[5];. It is still used today, for sure. When you just want a small set of objects or variables for the duration of a function, or as a data member of a class. However, technically-speaking, the C++11 standard introduced the std::array class template which can replace a static array and has a number of benefits, such as being copyable, and usable like an STL container.

What confuses you about static arrays?

Bounded array means static it it?

Bounded array means static it it?

"Bounded" typically means one of two things:

  1. The size of a container is fixed and cannot change.
  2. Accessing indices outside of the container's range will produce an exception.

Can you clarify what you mean by "bounded"? I'm also not familiar with that as any kind of standard terminology. IIRC, the C++ standard only mentions "bounded" in reference to numeric ranges and syntax grammar; nothing about arrays.

int&put(int i);
int get(int i);
int vals[10];
int error= -1;
int main()
 {
   int i;
   put(0)=8;
   put(3) =5;
   put(2)=7;
   cout << get(0) << " " << endl;
   cout << get(3) << " " << endl;
   cout << get(2) << " " << endl;

   return 0;


 }
 int & put(int i)
 {
    if(i> 0 && i< 10)
    return vals[i];

    else 
    {
      cout << "Bound Error";
      return error;


    }

 }
 int get (int i)
 {
    {
    if(i> 0 && i< 10)
    return vals[i];

    else 
    {
      cout << "Bound Error";
      return error;


    }

 }
 }


 ///so in this content bound means  fixed/static array?

In that example, the vals array would be called a static array or fixed-size array. But, the tests that are done in the get and put functions would be called "bound-checking" or bounded array access (I.e., the array access is "bounded"). So this might explain how you got the term "bounded array" from.

commented: you beat me too it +8

In your example, you're writting a wrapper for a static array that adds bounds checking.

If that example is from a book, I would probably look for a better book. (for use of globals, for static array size and for some small strange bits of syntax).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.