3_Variables_Operators

3_Variables_Operators - Variables and Operators 1 CMPE13...

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

View Full Document Right Arrow Icon
CMPE13 Cyrus Bazeghi Variables and Operators 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
CMPE13 B ASIC C E LEMENTS Variables named, typed data items Operators predefined actions performed on data items combined with variables to form expressions, statements Rules and usage 2 2
Background image of page 2
CMPE13 “S TANDARD ” D ATA T YPES Type Bytes Range short int 2 -32,768 -> +32,767 (32kb) unsigned short int 2 0 -> +65,535 (64Kb) unsigned int 4 0 -> +4,294,967,295 ( 4Gb) int 4 -2,147,483,648 -> +2,147,483,647 ( 2Gb) long int 4 -2,147,483,648 -> +2,147,483,647 ( 2Gb) signed char 1 -128 -> +127 unsigned char 1 0 -> +255 float 4 Big double 8 Bigger long double 12 Biggest 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
CMPE13 V ARIABLE N AMES Any combination of letters, numbers, and underscore (_) Case matters "sum" is different than "Sum" Cannot begin with a number usually, variables beginning with underscore are used only in special library routines Only first 31 characters are used 4 4
Background image of page 4
CMPE13 E XAMPLES Legal i wordsPerSecond words_per_second _green aReally_longName_moreThan31chars aReally_longName_moreThan31characters Illegal 10sdigit ten'sdigit done? double 5 reserved keyword same identifier 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
CMPE13 L ITERALS Integer 123 /* decimal */ -123 0x123 /* hexadecimal */ Floating point 6.023 6.023e23 /* 6.023 x 10 23 */ 5E12 /* 5.0 x 10 12 */ 6 6
Background image of page 6
CMPE13 L ITERALS Character 'c' '\n' /* newline */ '\xA' /* ASCII 10 (0xA) which is a newline*/ 7 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
CMPE13 S COPE : G LOBAL AND L OCAL Where is the variable accessible? Global: accessed anywhere in program Local: only accessible in a particular region 8 8
Background image of page 8
CMPE13 S COPE : G LOBAL AND L OCAL Compiler infers scope from where variable is declared programmer doesn't have to explicitly state Variable is local to the block in which it is declared block defined by open and closed braces { } can access variable declared in any "containing" block Global variable is declared outside all blocks 9 9
Background image of page 9

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

View Full DocumentRight Arrow Icon
CMPE13 E XAMPLE #include <stdio.h> int itsGlobal = 0; main() { int itsLocal = 1; /* local to main */ printf("Global %d Local %d\n", itsGlobal, itsLocal); { int itsLocal = 2; /* local to this block */
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 36

3_Variables_Operators - Variables and Operators 1 CMPE13...

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

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