This is my example:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int ar[][3] = {1, 2, 3, 4, 5, 6, 7};
//cout << int[3]<<endl; // error C2062: type 'int' unexpected.
cout << "sizeof(ar) / sizeof(int[3]) "<< sizeof(ar) / sizeof(int[3]) << endl;;
system("pause");
return 0;
}
It is from a book, though no explanation was given. What is int[3] here and why it works only as an argument of sizeof in this case?
int[3]is a type declaration that represents an array of three integers.Your commented code gives an error because you can’t use a type as a variable.