搜尋此網誌

[C/C++][動態一維陣列的使用]

/*
* File Name: Dynamic1DimentionalArray.cpp
* Author: MH
* Since 2013/03/03
* Toolkit: Dev C++ 4.9.9.9
*/

#include <iostream>

using namespace std;

int main(){

    int size, i, *q;

    cout << "enter the size: ";
    cin >> size;

    q = new int [size];    // generating

    for (i=0; i<size; i++)    // accessing: assigning values
        q[i] = i;
    for (i=0; i<size; i++)    // accessing: printing values
        cout << q[i] << " ";

    // deallocate the memory when no longer needed
    delete []q;

    return 0;
}

沒有留言:

張貼留言