Printing an array in C++?

前端 未结 10 1254
谎友^
谎友^ 2020-11-27 14:35

Is there a way of printing arrays in C++?

I\'m trying to make a function that reverses a user-input array and then prints it out. I tried Googling this problem and i

10条回答
  •  臣服心动
    2020-11-27 15:11

    My simple answer is:

    #include 
    using namespace std;
    
    int main()
    {
        int data[]{ 1, 2, 7 };
        for (int i = sizeof(data) / sizeof(data[0])-1; i >= 0; i--) {
            cout << data[i];
        }
    
        return 0;
    }
    

提交回复
热议问题