ECS 30 Lecture Notes - Lecture 14: Switch Statement, Infinite Loop, Segmentation Fault
![](https://new-preview-html.oneclass.com/rKZ3w4gpqWELjZVEXEyej8nX2G5YyBMv/bg1.png)
Lecture 14
See powerpoint for code lines
Dynamic size
- The size of the initialization list determines the number of elements
Example:
#include <stdio.h>
int main(void)
{
int primes[] = { 2, 3, 5, 7, 11 };
printf("2nd prime number is: %d\n",
primes[1]);
return 0;
Indexing
- Any expression that produces an integer can be used as subscript
- As long as subscript stays within bounds (see powerpoint for code line)
Loops
- Very often arrays are meant to be sequentially accessed
o For loop is the perfect repetition structure
o Use of a constant for the array size is always recommended
o A loop becomes an infinite loop if a condition never becomes false.
o When the conditional expression is absent, it is assumed to be true. You may
have an initialization and increment expression, but C programmers more
commonly use the for(;;) construct to signify an infinite loop.
Example:
#include <stdio.h>
find more resources at oneclass.com
find more resources at oneclass.com