week5 - Unix C + GNU HTML Perl Python The C Programming...

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

View Full Document Right Arrow Icon
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 1 The C Programming Language Comp-206 : Introduction to Software Systems Week 5 Joseph Vybihal Computer Science McGill University
Background image of page 1

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

View Full DocumentRight Arrow Icon
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 2 Announcements
Background image of page 2
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 3 Part 1 Basic C Statements and Expressions
Background image of page 3

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

View Full DocumentRight Arrow Icon
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Arithmetic Operations C provides the basic arithmetic operations : + - * / The modulus (%) operator is also provided. For efficiency purposes, it also provides an increment and decrement operators : ++ -- += -= *= /= %= etc. Note that / operation for float and integer is very different. Unless both operands are float, the division will be integer based.
Background image of page 4
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 5 No BOOLEAN Type Uses INT: Integer 0 = false Any other number = true Math and boolean? (is it an even number?) int x = 10; if (x) printf (“TRUE!”);
Background image of page 5

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

View Full DocumentRight Arrow Icon
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Comparison Operators C provides the following comparison operators: == : equality != : not equal < : smaller than > : greater than <= : smaller or equal than >= : greater or equal than Please note that testing for equality is done using the == operator, which is not the same as = if ( a == 1 ) { // Good test if ( a = 1 ) { // Assigns the value of 1 to a // and will always test as true int x = 5 < 10;
Background image of page 6
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 Logical Operators C provides the following logical operator: || : OR ! : NOT These can be used with the comparison operators: if ( (a == 5) || (a == 6) ) // a = 5 or 6 if ( !(a == 5) ) // a is not 5 if ( a != 5 ) // a is not 5 int x = (a == 5) || (a == 6);
Background image of page 7

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

View Full DocumentRight Arrow Icon
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 8 Bit operators | Logical OR >> Shift right << Shift left ~ one’s complement Examples. ..
Background image of page 8
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 9 Characters Every character is stored as a number, including spaces, digits, and punctuation Corresponding upper and lower case letters are separate characters H i , H e a t h e r . 72 105 44 32 72 101 97 116 104 101 114 46
Background image of page 9

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

View Full DocumentRight Arrow Icon
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 10 Characters in C Syntax : SCOPE MODIFIER char VARNAME = ‘C’; A single character in single quotes 67 VARNAME Stored as an integer number (a code in integer) 8 bits start address Math with characters. .. encryption
Background image of page 10
Unix C + GNU HTML Perl Python COMP 206 - Joseph Vybihal 2007 11 Strings in C Syntax : SCOPE MODIFIER char* VARNAME = “characters”; Many characters in double quotes ‘c’ ‘h’ ‘a’ ‘r’ ‘a’ ‘c’ ‘t’ ‘e’ ‘r’ ‘s’ 8 bits start address ‘\0’ The NULL character Printf w/o NULL?
Background image of page 11

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

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

Page1 / 44

week5 - Unix C + GNU HTML Perl Python The C Programming...

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

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