02CIntroSmall

02CIntroSmall - CMSC 106 Lecture Set #2 C Language...

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

View Full Document Right Arrow Icon
1 CMSC 106 Lecture Set #2 C – Language Introduction C language – syntax s Syntax s rules of the grammar s vocabulary recognized by the language s ANSI standard s American National Standards Institute s Semantics s the meaning of what is being said Syntax vs Semantics Examples s The monster scared Jon. s syntactically valid s Jon scared the monster. s syntactically valid s says something different than the first. s Jon sat in the chair. s syntactically valid s The chair sat in Jon. s syntactically valid s questionable in semantics s The in sat. Chair Jon s Syntactically invalid s no semantic interpretation from this available at all
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Program Errors s Incorrect Syntax s The compiler gives error message at that spot and refuses to compile it. s The compiler gives warning message at that spot but still compiles it. s The compiler gives error or warning message at a spot later in the file. s Incorrect Semantics s Program does nothing when run s Program does nothing useful when run s Program does the “wrong” thing when run s Program “crashes” or “hangs” when running Basic Program Structure s a program must be comprised of 1 or more functions s function = named program part for performing a specific task s must be 1 and only 1 function named main s controls everything else s starts there and determines who gets to go when s for now this is the only function you’ll design Functions: Definition and Use s Syntax of a function definition: funct_type funct_name ( list_of_parameters ) { funct_body } Example of a complete program: int main(){ printf("this is a complete program\n"); } Syntax of a function call funct_name(list_of_arguments); Example of a function call: printf("This is a complete program\n");
Background image of page 2
3 Functions: Identified by Name s Identifiers s Used to name functions, variables, etc.
Background image of page 3

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

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

Page1 / 7

02CIntroSmall - CMSC 106 Lecture Set #2 C Language...

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