C++使用大括号给数组赋初值

2023-12-15 18:36:30

以下写法都是合法;

void CDkhView::OnDraw(CDC* pDC)
{
	CDkhDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CString str1;

	int arr1[5] = {0};
    str1.Format("%d, %d, %d, %d, %d", arr1[0], arr1[1], arr1[2], arr1[3], arr1[4]);
	pDC->TextOut(20, 20, str1);

	int arr2[5] = {99, 77, 33, 55, 66};
    str1.Format("%d, %d, %d, %d, %d", arr2[0], arr2[1], arr2[2], arr2[3], arr2[4]);
	pDC->TextOut(20, 50, str1);

	int arr3[] = {9, 7, 3, 5, 6, 6};
    str1.Format("%d, %d, %d, %d, %d, %d", arr3[0], arr3[1], arr3[2], arr3[3], arr3[4], arr3[5]);
	pDC->TextOut(20, 80, str1);

	int arr4[8] = {9, 71, 31, 5};
    str1.Format("%d, %d, %d, %d, %d, %d, %d, %d", arr4[0], arr4[1], arr4[2], arr4[3], arr4[4], arr4[5], arr4[6], arr4[7]);
	pDC->TextOut(20, 110, str1);

	int a[3][4] = {
  {1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
	int row=0;
	for(int i=0; i

文章来源:https://blog.csdn.net/bcbobo21cn/article/details/134917394
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。