🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to C Notes
Topic #48

Array Size


Get Array Size

To get the size of an array, you can use the sizeof operator:

Example

int myNumbers[] = {10, 25, 50, 75, 100};

printf("%zu", sizeof(myNumbers));  // Prints 20

Note: Why did the result show 20 instead of 5, when the array contains 5 elements?

  • It is because the sizeof operator returns the size of a type in bytes.

You learned from the Data Types chapter that an int type is usually 4 bytes, so from the example above, 4 x 5 (4 bytes x 5 elements) = 20 bytes.

Knowing the memory size of an array is great when you are working with larger programs that require good memory management.

But what if you just wanted to know how many elements the array was storing?


Get the Number of Elements

If you want to find out how many elements an array has, you can use this formula, which divides the total size of the array by the size of one element:

Example

int myNumbers[] = {10, 25, 50, 75, 100};
int length = sizeof(myNumbers) / sizeof(myNumbers[0]);

printf("%d", length);  // Prints 5

The sizeof formula works for arrays of any type and any size:

Example

double myValues[] = {1.1, 2.2, 3.3};
int length = sizeof(myValues) / sizeof(myValues[0]);

printf("%d", length);  // Prints 3

Note: In the next chapter, you will see how to use this formula to make loops that automatically adapt to the array size.

Want to go beyond the notes?

Join CodingNow 2.0's C course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Array Size – FAQs

Quick answers about learning Array Size in C.

This free note from CodingNow 2.0 explains Array Size in C — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C topic on CodingNow 2.0, including Array Size, is 100% free with no signup required.
With focused practice, most students grasp Array Size in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now