Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
95 views
in Technique[技术] by (71.8m points)

c++ - What does int a[MAX] do and what does it mean

I’m talking about line 4 after public:

class Stack {
        int top;
     
    public:
        int a[MAX]; // Maximum size of Stack
     
        Stack() { top = -1; }
        bool push(int x);
        int pop();
        int peek();
        bool isEmpty();
    };
     
    bool Stack::push(int x)
    {
        if (top >= (MAX - 1)) {
            cout << "Stack Overflow";
            return false;
        }
        else {
            a[++top] = x;
            cout << x << " pushed into stack
";
            return true;
        }
    }

UPDATE: Because others have commented on it, I just wanted to clarify that I know what an array is and how to use one and I have read documentations before. I just needed help in understanding how it is used inside classes. Also, I would like to thank the people who helped me by answering the question. I appreciate it very much!

question from:https://stackoverflow.com/questions/65624103/what-does-int-amax-do-and-what-does-it-mean

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What does int a[MAX] do and what does it mean

It is declaration of a variable whose name is a and type is int[MAX] which is an array of MAX number of int elements.

I just needed help in understanding how it is used inside classes

When variable declaration is inside a class, it declares a member variable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...