lect03 - 9/9/11 1 CMSC 216 Introduction to Computer Systems...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 9/9/11 1 CMSC 216 Introduction to Computer Systems Lecture 3 Introduction to C Jan Plane & Pete Keleher {jplane, keleher}@cs.umd.edu Administrivia Project 1 posted tomorrow, due Sept. 18 public tests available in public Grace directory soon Read Chapters 4 and 5 of Reek CMSC 216 - Wood, Sussman, Herman 2 9/9/11 2 STATEMENTS Chapter 4, Reek CMSC 216 - Wood, Sussman, Herman 3 Assignment statements Any expression can appear as a statement An assignment is just an expression (typically used as an expression statement) The = is an operator in C (and right associative) legal expression statements, assuming int x, y; x = 3; y + 3; x == y; An expression statement is useful when the expression has a side effect An assignment returns a value - whatever value was assigned to the variable on the left hand side of the assignment y = x = 123; y = 5 + (x = 3); CMSC 216 - Wood, Sussman, Herman 4 9/9/11 3 C control statements These are very similar to Java, with one important difference: C has no boolean type scalar expressions used instead; 0 is false, everything else is true C has if / else , while , for , do- while , and switch statements, just as Java does but can't declare variables in for loop header break : immediately end loop continue : skip remainder of loop body, return to beginning of loop in case of for loop, perform increment don't abuse break / continue, and rarely use continue if at all CMSC 216 - Wood, Sussman, Herman 5 Perfectly valid boolean examples int c = ??? ; if (c) f1(); if (c != 0) f2(); if (c == 2) f3(); if (c = 2) f4(); Function -1 0 1 2 f1() Y N Y Y f2() Y N Y Y f3() N N N Y f4() Y Y Y Y CMSC 216 - Wood, Sussman, Herman 6 The table shows which functions will be executed if certain values are assigned to c during its initialization....
View Full Document

This note was uploaded on 01/13/2012 for the course CMSC 216 taught by Professor Plane during the Spring '11 term at Maryland.

Page1 / 12

lect03 - 9/9/11 1 CMSC 216 Introduction to Computer Systems...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online