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,851 questions

51,772 answers

573 users

How to determine the size (row, col) of two dimensional array (array[][]) in C

2 Answers

0 votes
#include <stdio.h>
 
int main(void)
{
    char s[][5] = { "AB12" , "CD98" , "AB34" };
 
	printf("char size: %d\n", (int)sizeof(char));
	printf("Total size: %d\n", (int)sizeof(s));
    printf("Col size: %d\n", (int)sizeof(s[0]));
    printf("Row size: %d\n", (int)(sizeof(s)/sizeof(s[0])));
     
    return 0;
}
 
  
/*
    
run:
    
char size: 1
Total size: 15 // 5 x 3
Col size: 5
Row size: 3
 
*/

 



answered Jan 27, 2016 by avibootz
edited Jan 27, 2016 by avibootz
0 votes
#include <stdio.h>

int main(void)
{
	int n[][5] = { {12 , 652 , 7}, {23, 54, 98}, {98, 48, 100} };

	printf("int size: %d\n", (int)sizeof(int));
	printf("Total size: %d\n", (int)sizeof(n));
	printf("Col size: %d\n", (int)sizeof(n[0]));
	printf("Row size: %d\n", (int)(sizeof(n)/sizeof(n[0])));
	
	return 0;
}

 
/*
   
run:
   
int size: 4
Total size: 60 // 5 x 4 x 3
Col size: 20 // 5 x 4
Row size: 3

*/

 



answered Jan 27, 2016 by avibootz
...