使用memset设置二维数组内容

#include
#include
using namespace std;
int main()
{
    int a[10][10];
    memset(a, 0, sizeof(a)); //将二维数组每个字节都设置为0

    for(int i = 0; i < 10; i ++)
    {
        for(int j = 0; j < 10; j ++)
        {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
    
    char b[10][10];
    memset(b, 'A', sizeof(b));
    for(int i = 0; i < 10; i ++)
    {
        for(int j = 0; j < 10; j ++)
        {
            cout << b[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

你可能感兴趣的:(C语言,C++,c++,算法,c语言)