ECS 30 Lecture Notes - Lecture 14: Switch Statement, Infinite Loop, Segmentation Fault

46 views2 pages
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
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents