Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,819 answers

573 users

How to get int array size uisnf macro regardless of array type in C

3 Answers

0 votes
#include <stdio.h>

#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
 
int main()
{
    int arr[] = {4, 9, 0, 1, 8};
 
    printf("%d\n", ARRAY_SIZE(arr));
 
    return 0;
}
 
 
           
/*
run:
        
5
 
*/

 



answered Feb 9, 2025 by avibootz
0 votes
#include <stdio.h>

#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
 
int main()
{
    char arr[] = {'a', 'b', 'c', 'd', 'e', 'f'};
 
    printf("%d\n", ARRAY_SIZE(arr));
 
    return 0;
}
 
 
           
/*
run:
        
6
 
*/

 



answered Feb 9, 2025 by avibootz
0 votes
#include <stdio.h>

#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
 
int main()
{
    float arr[] = {3.14, 5.012, 0.3, 0.07};
 
    printf("%d\n", ARRAY_SIZE(arr));
 
    return 0;
}
 
 
           
/*
run:
        
4
 
*/

 



answered Feb 9, 2025 by avibootz

Related questions

2 answers 272 views
1 answer 162 views
1 answer 139 views
1 answer 106 views
106 views asked Jan 8, 2024 by avibootz
1 answer 119 views
1 answer 165 views
...