Programming Tips 💡
51.6K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips 💡
Articles 📕
Resources 👾
Design Patterns 💎
Software Principles ✅

🇳🇱 Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
📦 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:
#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