



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Introduction to Computer Programming; Subject: Computational Science; University: Syracuse University; Term: Unknown 1989;
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




int ages[4]; ages[0] ages[1] ages[2] ages[3] definition. Sets up memory ages[2] = 5; we can assign to an array element int n; We can use ages[2] anywhere we can use n. ex: t = 3 * ages[1]; formula if (ages[3] > 65 ); comparison abs( ages[2]); as an argument scanf("%d", &ages[0] ); in a scanf
double x[3] = { 1.1, 2.2, 3.3 }; initialization x[0] x[1] x[2] int m[ ] ={2, 4, 6 } m[0] m[1] m[2] int n[4] = { 5, 10 } n[0] n[1] n[2] n[3]
int t[5]; int i; for ( i=0; i<5; i++) t[i] = 2*i; t[0] t[1] t[2] t[3] t[4] i If we now try: t = { 3, 6, 9, 12, 15 }; illegal! Only works when first declare variable. t[5] = 10; computer doesn't complain. Very bad. Something gets messed up. printf("%d", t[-1]); Computer doesn't complain. Prints junk.
char word[9] = "computer" int i; word [0] [1] [2] [3] [4] [5] [6] [7] [8] i for (i=7; i>=0; i--) printf("%c", word[i] ); output: retupmoc c o m p u t e r \ 0