


















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
The key points in these lecture slides of intro to computer programming are given as:Arrays, Group of Items, One Variable Name, Same Data Type, One Dimensional Array, Thinking About Arrays, Declaring Arrays, Assigning Values to Arrays, Index, Number in Brackets, Program Example
Typology: Slides
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















Lecture 15
myptr = &myarray[2]; /* Assign the address of the third element of myarray to myptr */ printf(“%d”, myptr); / Print the value of what myptr is pointing to, i.e., the value of myarray[2] */
/* Printing array values and addresses */ #include <stdio.h> int main ( ) { int k; float a[4] = {1000, 2000, 3000, 4000}; printf ("k a &a[k] a[k]\n"); for (k=0; k<4; k++) printf ("%d %ld %ld %f\n", k, a, &a[k], a[k]); }
/* Passing an array to a function */ #include <stdio.h> #include <string.h> void myfunct (int , char [ ]); int main ( ) { char name[20] = "Michael J. Miller"; myfunct (20, name); }
Given the declaration
int b[3][3] = {{1,3,5}, {7,9,11}, {13,15,17}};
b is a pointer to b[0][0] b[0] is also a pointer to b[0][0] b[1] is a pointer to b[1][0] b[2] is a pointer to b[2][0] *b is a pointer to b[0] (special case) *b[1] is the value of b[1][0] (which is 7) *b[2] + 1 is the value of b[2][0] + 1 Docsity.com
void printarray (int cal[][7],
int j)
{
int k, n ; for (k = 0 ; k < j ; k++) { for (n = 0 ; n < 7 ; n++) printf ("%3d ", cal[k][n]); Docsity.com
/* Double subscript arrays, user-written functions and pointer arithmetic */
#include <stdio.h>
void printarray (int * , int , int);
int main ( ) {
int calendar[5][7]= {{1,2,3,4,5,6,7}, {8, 9, 10,11,12,13,14},
there are several lines of "header" information followed by many lines of data in four columns.
beginning of the file until you get to a line that has the actual data in the four columns. (You will need this number in Step 2 later.)
just use the usual fopen routine.
rather convenient to read the complete line into a character array or string.