C Array Loop
1. Looping Through an Array Using for Loop
-
The most common way to process array elements is with a
forloop. -
Example: Print all elements of an array
Output:
2. Sum of Array Elements Using for Loop
Output:
3. Finding Maximum Element Using for Loop
Output:
4. Using while Loop to Traverse Array
Output:
5. Using do...while Loop to Traverse Array
Output:
6. Key Points
-
Loop variable usually starts from 0 (first index).
-
Loop continues while index
< sizeof the array. -
Can use
for,while, ordo...whileloops to traverse arrays. -
Use loops to perform sum, search, max/min, or modify elements efficiently.
-
Avoid accessing indices beyond array size — causes undefined behavior.
