L04 - CME/Energy 211 Margot Gerritsen Shela Aboud Emmet...

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

View Full Document Right Arrow Icon
CME/Energy 211 Margot Gerritsen Shela Aboud Emmet Caulfield
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture Overview • Basic Structure of C code • Variables • Data Types: int , float , double , char , void • Declarations: local, function, global • Operators: arithmetic, relational, logical, bitwise • Expressions: order of evaluation, type conversion, cast
Background image of page 2
C Code Structure /********************************************************************************/ /* */ /* The first C program: Hello World : */ /* */ /*********************************************************************************/ #include<stdio.h> /*include information about standard library */ int main(void) /*define a function named main that */ /*receives no argument values */ { /* statements of main are enclosed in braces*/ printf(“Hello World\n”); /*main calls library function printf to print */ /*this sequence of characters; \n represents */ /*the newline character */ return 0; /* return value 0 to shell */ } /***********************************************************************************/
Background image of page 3

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

View Full DocumentRight Arrow Icon
Variables • Identifiers are made up of letters, digits and underscores. • First character must be a letter or underscore • Names beginning with an underscore are reserved or have a special use. • Cannot use keywords. • C is case sensitive. Traditionally use all lowercase for variable names and all uppercase for manifest constants (#define) • Can be any length, but not all characters may be significant in all cases. A variable is a named location in memory used to hold a value that may be modified by the program. A variable name must be a valid identifier .
Background image of page 4
31 ANSI C Keywords auto break case char const continue default do int long register return short signed sizeof static Other C complier based keywords exist main() is like a keyword case sensitive Keywords may not be used as variable names (or other identifiers) double else enum extern float for goto if struct switch typedef union unsigned void volitile while
Background image of page 5

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

View Full DocumentRight Arrow Icon
Variable Names - Examples Correct TYPE1 Type1 type1 type_1 Not Correct/poor choice _myvariable _Myvariable __myvariable 4myvariable case main l
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

L04 - CME/Energy 211 Margot Gerritsen Shela Aboud Emmet...

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

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