Lesson 11 of 23

Arrays

9 min 25 XP

An array stores values of one type in consecutive memory. Indexes start at 0. C does not check bounds: writing a[10] in a 5-element array corrupts memory, so be careful!

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

sizeof(arr) / sizeof(arr[0]) gives the number of elements, but only in the function where the array was declared.

Challenge

+25 XP

Read n and n distinct numbers, then print the second largest. Input: 5 3 8 1 9 4 Output: 8

Output Loading C (first time takes a few seconds)
Press Run to see the result here.