newOverview

newOverview - Chapter2 Overview of C ASampleProgram This is...

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

View Full Document Right Arrow Icon
Chapter 2 Overview of C++
Background image of page 1

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

View Full DocumentRight Arrow Icon
A Sample Program // This is my first program. It calculates and outputs // how many fingers I have. #include <iostream> using namespace std; int main () { int digits; digits = 5*2; cout << "I have " << digits << " fingers" << endl; return 0; }
Background image of page 2
C++ Language Elements Comments Compiler directives Function main Declaration statements Executable statements
Background image of page 3

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

View Full DocumentRight Arrow Icon
Comments Used to explain code to author and other readers /* */ (multi-line, "C style") // (until end of line, "C++ style") Write good meaningful comments! There is a bad example on class page under: Other Useful Links Don't repeat code in a comment, explain it!
Background image of page 4
#include < filename > this is a compiler directive (starts with #) Includes previously written code from a library into your program E.g. #include <iostream> has operators for performing input and output within the program Libraries allow for code reuse
Background image of page 5

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

View Full DocumentRight Arrow Icon
using namespace std; Indicates to compiler that this program uses objects defined by a standard namespace called std The statement ends with a semicolon Follows #include directives in the code Must appear in all programs
Background image of page 6
The main function Every C/C++ program must have a function named main and only ONE called main The start of the main function is the marker for the start of the program execution int main ( ) { // function body return 0; }
Background image of page 7

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

View Full DocumentRight Arrow Icon
    What is in a function heading  (header)?  int main( ) type of returned value name of function () says no parameters 8
Background image of page 8
The main function header is int main () // NOT "void main" empty () in header means no parameters, indicates no special information passed to the function by the operating system braces {} around body must balance semicolons mark ends of statements return 0; at the end of the function "satisfies" the int return value in the header
Background image of page 9

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

View Full DocumentRight Arrow Icon
Code and Data Almost every statement in the program is concerned with manipulating data inputting it outputting it calculating with it making decisions based on its values storing it temporarily or permanently
Background image of page 10
Data Properties has a name - either itself or an identifier has a type - integer, character, float, string, etc. has space in RAM and an address = memory
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 / 37

newOverview - Chapter2 Overview of C ASampleProgram This is...

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