📦 Macro To Get Array Size Of Any Data Type In C 📦
The following macro will help you in getting the size of an array of any data type. It works by dividing the length of the array to the size of its field. 💡
Code:
Output:
#c #cpp #array
@ProgrammingTip
The following macro will help you in getting the size of an array of any data type. It works by dividing the length of the array to the size of its field. 💡
Code:
#define num(x) (sizeof (x) / sizeof (*x))
int _tmain() {
int numbers[10] =
{1,1,1,1,1,1};
char *chars[20] =
{"","","","","","","","",""};
printf("Size of numbers[10] is %d\n",
num(numbers));
printf("Size of chars[20] is %d\n",
num(chars));
}
Output:
Size of numbers[10] is 10
Size of chars[20] is 20
Press any key to continue . . .
#c #cpp #array
@ProgrammingTip