CS137 Lecture Notes - Lecture 10: Scilab, Call Stack, C Syntax
Document Summary
Functions can be passed as arguments: double f(double x); //f=3x2+3x+3 int main () printf( %g\n , bisect (-10, 10, 0. 001, 100000, f0)); printf( %g\n , bisect (-10, 10, 0. 001, 100000, f1)); return 0; Compound data types: groups several named member variables (fields) //time of day struct tod int hours; int minutes; int main () struct tod now = (16, 50); struct tod later; later. hours = 18; later. minues = 0; printf ( %d:%d\n , now. hours, now. minues); printf( %d:%d\n , later. hours, later. minutes); return 0; // better way, as parameters/arguments void todprint (struct tod when) int main() Program trace (call stack) struct tod later = {18,0}; todprint (later); return 0; Returning structs when. minutes +=minutes; when. hours += hours + whenminutes/60; when. minutes %= 60; when. hours %=24; return when; Example struct tod todaddtime (struct tod when, int hours, int minutes) int main () //18:00 struct tod now={16,50}; now = todaddtime (now, 1, 10); todprint(now); return 0;