Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
21
Task/Array-length/C/array-length-1.c
Normal file
21
Task/Array-length/C/array-length-1.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
const char *fruit[2] = { "apples", "oranges" };
|
||||
|
||||
// Acquire the length of the array by dividing the size of all elements (found
|
||||
// with sizeof(fruit)) by the size of the first element.
|
||||
|
||||
// Note that since the array elements are pointers to null-terminated character
|
||||
// arrays, the size of the first element is actually the size of the pointer
|
||||
// type - not the length of the string.
|
||||
|
||||
// This size, regardless of the type being pointed to, is 8 bytes, 4 bytes, or
|
||||
// 2 bytes on 64-bit, 32-bit, or 16-bit platforms respectively.
|
||||
int length = sizeof(fruit) / sizeof(fruit[0]);
|
||||
|
||||
printf("%d\n", length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue