Download presentation
Presentation is loading. Please wait.
1
Glenn Stevenson CSIS 113A MSJC
Introduction To C++ Glenn Stevenson CSIS 113A MSJC
2
Glenn Stevenson CSIS 113A MSJC
Overview Of A Computer The Hardware CPU Disk I/O Devices Memory Glenn Stevenson CSIS 113A MSJC
3
Glenn Stevenson CSIS 113A MSJC
Memory The Memory Memory is addressed by byte In our Windows machines 1 byte = 8 bits Each bit can be 0 or 1 Memory can hold Program instructions Data 000 001 002 003 004 005 006 007 008 … Max Glenn Stevenson CSIS 113A MSJC
4
Glenn Stevenson CSIS 113A MSJC
Memory II The Memory Memory is split into space for program instructions and for data Data space is usually further subdivided Static/constant Stack Heap Program Instructions Data Glenn Stevenson CSIS 113A MSJC
5
Glenn Stevenson CSIS 113A MSJC
CPU And Memory The CPU Program Counter Instruction register Other Registers Memory Other Registers ... Other Registers In our Windows machines these registers are 32 bits wide ALU Glenn Stevenson CSIS 113A MSJC
6
Glenn Stevenson CSIS 113A MSJC
The OS Operating System Windows Linux Applications Editor Compiler The programs we will write Applications Operating System APIs Drivers Hardware = Software Glenn Stevenson CSIS 113A MSJC
7
Developing C++ Programs
Steps to develop a program Write C++ instructions, store in source-code file The following two steps are usually automated Use compiler to turn source into object code Use linker to create executable Use a debugger to examine and test program Standalone tools vs. an IDE Integrated Development Environment combines tools You should know how to use individual tools Glenn Stevenson CSIS 113A MSJC
8
Glenn Stevenson CSIS 113A MSJC
Compile, Link, Execute Source Code Object Code Preprocessor Compiler Comments (discarded) Linker .exe Glenn Stevenson CSIS 113A MSJC
9
Glenn Stevenson CSIS 113A MSJC
Comments Way to leave notes in your code Ignored by compiler You should use them liberally 2 types Single line // Everything after the double slash is a comment up to the end of the line Multi-line /* */ /* everything between Is a comment */ Glenn Stevenson CSIS 113A MSJC
10
Glenn Stevenson CSIS 113A MSJC
Required for homework All assignments must have comments at the top of each page! /* Name: Glenn Stevenson SID#: Date: todays date Lab #: 1 Description: you can simply copy and paste from the assignment descript itself */ Failure to add comments to your assignments can result in a 0 grade Glenn Stevenson CSIS 113A MSJC
11
Glenn Stevenson CSIS 113A MSJC
Functions & main C++ is typically a cooperating group of functions Functions Like a small program within a large program Used to perform a specific task main – function where your program begins Your program must have a main function Programs need a place to start Program will not link without a main function Glenn Stevenson CSIS 113A MSJC
12
Glenn Stevenson CSIS 113A MSJC
Anatomy of main C++ is a case Sensitive language Function Header First line of function Function Body Code between opening and closing braces All blocks have an opening and a closing brace Return Statement What this function returns Where does in return to? Glenn Stevenson CSIS 113A MSJC
13
Glenn Stevenson CSIS 113A MSJC
Statements / Blocks Statements Any valid line of C++ code Statements are terminated by a semicolon Can span multiple lines compiler looks for ; as a marker Compiler generates an error when a statement is not terminated by a semicolon Blocks Any code that has an opening & closing brace Not terminated by a semicolon Function main has opening and closing brace Function body then is a block of code Glenn Stevenson CSIS 113A MSJC
14
Glenn Stevenson CSIS 113A MSJC
Our First Program! // myfirst.cpp - A simple C++ program #include <iostream> // Preprocessor statement using namespace std; // Make cout visible int main() // Function header { cout << "Hi, my name is Glenn Stevenson"; cout << "\n"; return 0; } Glenn Stevenson CSIS 113A MSJC
15
Ananlyizing myFirst.cpp
#include <iostream> Has definitions input and output streams C++ has much functionality included using namespace std; Use built functionality from standard library int main() Function header of main followed by the body of main (code between the baces) cout << “Hi my name is Glenn Stevenson”; cout puts information to screen cout << “\n”; Moves the cursor to the next line on the console window Called an escape character, more about that later Glenn Stevenson CSIS 113A MSJC
16
What is wrong with this code?
// myfirst.cpp - A simple C++ program #include <iostream> // Preprocessor statement using namespace std; // Make cout visible int Main(); // Function header { cout << "Hi, my name is Glenn Stevenson"; cout << "\n"; return 0; }; Glenn Stevenson CSIS 113A MSJC
17
Glenn Stevenson CSIS 113A MSJC
The preprocessor Separate program called CPP [C Pre-Processor] Massages source code before giving it to compiler Preprocessor instructions are called directives Preprocessor directives all begin with # The #include <iostream> directive says "Send the declarations and definitions in the iostream header to the compiler at this point" What is a "header"? "Family" of declarations and definitions Normally stored in a file (or translation unit as it is called in C++), but doesn't have to be Glenn Stevenson CSIS 113A MSJC
18
Glenn Stevenson CSIS 113A MSJC
The Preprocessor II #include <iostream> // Preprocessor statement Source Code Object Code Preprocessor Compiler Header Glenn Stevenson CSIS 113A MSJC
19
Glenn Stevenson CSIS 113A MSJC
The Preprocessor III Traditional [C-style] headers all end in .h Standard C++ headers: Don't have ".h" suffix Don't necessarily refer to file names Older [pre-IS0] compilers won't support Under Turbo C++, for instance, you write: #include <iostream.h> And don’t get namespace functionality Do not use the C-style headers C++ Style Guide 7.1.1 Glenn Stevenson CSIS 113A MSJC
20
Glenn Stevenson CSIS 113A MSJC
The Standard Headers 51 headers available in Standard C++ 18 ANSI C Standard library headers Available in traditional and new styles <stdio.h> and <cstdio> 13 Standard Template Library [STL] headers Collections and algorithms [generic programming] 9 Input/Output [I/0] stream headers String, exception, memory management, and various data structure classes not in the STL Glenn Stevenson CSIS 113A MSJC
21
Glenn Stevenson CSIS 113A MSJC
Namespaces using namespace std; // Make cout visible A namespace defines a region where names are valid In C, all function names are "global" Headers combine functions into "families" Namespaces combine families into "neighborhoods" All Standard C++ library functions and objects are in the std namespace C library functions also in std with new headers Some older compilers have not fully implemented this Glenn Stevenson CSIS 113A MSJC
22
Glenn Stevenson CSIS 113A MSJC
Namespaces II To use a function in a namespace Prefix it with namespace and :: [scope resolution] Example: using the standard sqrt() function #include <cmath> // In std namespace double ans = std::sqrt(5.25); In this class, you'll often import entire std namespace "Import" with using namespace declaration Glenn Stevenson CSIS 113A MSJC
23
Glenn Stevenson CSIS 113A MSJC
Literals Called literals because they are values that are literally stated 1 // integer literal – whole number 2.2 // floating point literal .3 // floating point literal 'h‘ // single character literal "Hello“ // string literal Don’t confuse single characters for strings! This is not legal ‘hello’ and ‘h’ is different from “h” Glenn Stevenson CSIS 113A MSJC
24
Glenn Stevenson CSIS 113A MSJC
C++ Output cout << "Hi, my name is Glenn Stevenson"; I/O is supplied as part of the standard library Definitions found in the <iostream> header Standard I/O is represented as a stream cout uses the stream extraction operator << notice that it points at cout! Can use many insertion operators to separate types Cout << “hello my lucky number is “ << 7 << endl; endl does the same thing as “\n” Moves cursor to next line on console window Glenn Stevenson CSIS 113A MSJC
25
Changing Numbers With cout
You can output numbers in many formats Send format type to cout Hexadecimal – Base 16 cout << hex << 16 << endl; Outputs 10 because 10 is 16 in hex Octal – Base 8 cout << oct << 9 << endl; Outputs 10 because 9 is 10 in octal Decimal – Base 10 cout << dec << 10 << endl; Outputs 10 Will output desired format until changed or program ends Glenn Stevenson CSIS 113A MSJC
26
Glenn Stevenson CSIS 113A MSJC
What is a stream? Streams are abstract information flows Data flows into your program from a source Your program processes the data Information flows out of your program to a sink Sending info to a sink is called writing Getting info from a source is called reading Glenn Stevenson CSIS 113A MSJC
27
Glenn Stevenson CSIS 113A MSJC
Standard streams C++ initially creates at least 3 stream objects Also known as standard input, output, and error cin : input connected to the keyboard cout : output connected to the monitor cerr : output connected to the monitor Glenn Stevenson CSIS 113A MSJC
28
Glenn Stevenson CSIS 113A MSJC
Formatting your code C++ is a free-form language Interchangably use spaces, tabs and newlines int main() { cout << "Hi"; return 0; } int main ( ) { cout << "Hi" ; return ; } Glenn Stevenson CSIS 113A MSJC
29
Glenn Stevenson CSIS 113A MSJC
Formatting II Cannot use whitespace between parts of a token A token is one or more characters with a single meaning /*, */, <<, // are all tokens Keywords like int and return are tokens Here are some uses of illegal whitespace with tokens in t main( ) { cout < < "Hi" ; ret urn 0; } You cannot put a literal newline in a string cout << “This is illegal”; cout << “But this ” “is legal!”; Glenn Stevenson CSIS 113A MSJC
30
Glenn Stevenson CSIS 113A MSJC
Code Formatting III Must use whitespace to separate some tokens cout<<"Hello there"; // Not required intmain(){return0;} // Spaces needed int main(){return 0;} // OK int main(){return(0);} // OK Glenn Stevenson CSIS 113A MSJC
31
Glenn Stevenson CSIS 113A MSJC
Values & Variables Values are discrete quantities of data Here are some values: 1, , “Glenn”, D, true Values represent different kinds of things In programming, this is called a value's type integers, real, text [strings], characters, Boolean Variables are: Named storage locations that hold values Every variable holds a value of a certain type The type defines the legal operations and the required memory to store it (size) Glenn Stevenson CSIS 113A MSJC
32
Glenn Stevenson CSIS 113A MSJC
Declaring Variables C++ has two statements devoted to variables Declaration statements and assignment statements A declaration statement specifies: The name of memory location The kind of thing (type) stored at the location int fleas; This creates an integer variable named fleas The compiler sets aside memory to store an int The amount of memory for an int is implementation dependent Makes sure that you use variable appropriately Cannot store a string in fleas, for instance Glenn Stevenson CSIS 113A MSJC
33
Glenn Stevenson CSIS 113A MSJC
Variable Definition I I like to think of the compiler taking a box of the correct size for the type of variable (a variable can be from 1 to n bytes in size), and writing the name, type of variable and its address on the outside. The box will hold the value of the variable when it’s used. The boxes are then stacked away in storage Name: i Type: int Address: 5000 Name: ch Type: char Address: 5004 Name: r Type: double Address: 5005 4 byte box 1 byte box 8 byte box Glenn Stevenson CSIS 113A MSJC
34
Variable Definition II
x int 5000 ch char 5004 r double 5005 5000 … x 5001 … 5002 … 5003 … … ch 5005 … r 5006 … 5007 … … Glenn Stevenson CSIS 113A MSJC
35
Glenn Stevenson CSIS 113A MSJC
LValues An LValue is nothing more than something that is to the left of the equal sign. Since values get assigned from right to left, the lvalue must alway be a variable . This means that you cannot do something like this: int x = 30; 25 = x; //Can’t Do this Glenn Stevenson CSIS 113A MSJC
36
Glenn Stevenson CSIS 113A MSJC
Variable Naming Rules Variable names can consist of letters, numbers, and the underscore but cannot begin with a number. They can also not be a C++ keyword like if, else, for, etc. Variable names cannot contain a space character. int my Var; // This is not valid int myVar; // This is valid Glenn Stevenson CSIS 113A MSJC
37
Glenn Stevenson CSIS 113A MSJC
Naming Conventions Naming conventions have changed over the years it used to be that if you had a variable name that had two words in it you would separate the words with an underscore. int my_int_variable; Later people starting capitalizing every word. int MyIntVariable; Currently, the convention is to capitalize from the second word on: int myIntVariable; Glenn Stevenson CSIS 113A MSJC
38
Glenn Stevenson CSIS 113A MSJC
Number Types C++ has several number types in two categories Integral Counting numbers Signed Unsigned Floating-point Real numbers (numbers with a fractional part) Glenn Stevenson CSIS 113A MSJC
39
Glenn Stevenson CSIS 113A MSJC
Numeric Type Sizes Name Bytes Range Digits short (also called short int) 2 -32,767 to +32,767 N/A int 4 -2,147,483,647 to +2,147,483,647 long (also called long int) float 10-38 to 10+38 7 double 8 to Approximately 15 long double 10 to Approximately 19 char 1 All ASCII Characters bool true, false Glenn Stevenson CSIS 113A MSJC
40
Glenn Stevenson CSIS 113A MSJC
Losing Precision Copying values from one type of a variable to another type can force a loss of data. double d = ; int x; x = d; x holds an integer value and the code is attempting to store double in it. These are different size buckets! the double will get truncated to an integer The value stored in x is 33. Glenn Stevenson CSIS 113A MSJC
41
Glenn Stevenson CSIS 113A MSJC
Losing Precision II You can put smaller values into bigger buckets because they will fit: . double d; int x = 30; d = x; //This is fine, no loss of data You may actually want to store a large value in a small bucket. You can do this without the compiler complaining by casting the value. Future topic Glenn Stevenson CSIS 113A MSJC
42
Glenn Stevenson CSIS 113A MSJC
Binary Numbers Unsigned (positive) binary integers Converting a binary number to decimal Each binary digit represents a power of 2 Just like decimal digits represent power of 10 So what is binary in decimal? = 181 Glenn Stevenson CSIS 113A MSJC
43
Glenn Stevenson CSIS 113A MSJC
Binary Numbers II So what’s 0x608bfa05 in decimal? 5 x 160 = 5 x 1 = 5 0 x 161 = 0 x 16 = 0 A x 162 = 10 x 256 = 2,560 F x 163 = 15 x 4096 = 61,440 B x 164 = 11 x = 720,896 8 x 165 = 8 x = 8,388,608 0 x 166 = 0 x = 0 6 x 167 = 6 x = 1,610,612, ,619,786,245 So = = 0x608bfa05 = 1,619,786,245 Glenn Stevenson CSIS 113A MSJC
44
Glenn Stevenson CSIS 113A MSJC
Binary Numbers III Converting a decimal number to binary Find largest power of 2 and subtract; repeat Example: Decimal 89 as binary Largest power of 2 is 64 : Subtract 64 from 89 = 25 Find next power of 2 [16] : Subtract 16 from 25 = 9 Find next power of 2 [8] : Subtract 8 from 9 = 1 Find next power of 2 [1] : = 0x59 Glenn Stevenson CSIS 113A MSJC
45
Glenn Stevenson CSIS 113A MSJC
Binary Number IV A way with a lot less work – convert to hex first Find the largest power of 16 and subtract the multiples Example: Decimal 89 as binary Largest power of 16 is 16: 0x50 Subtract 5 * 16 from 89 = 9 Next smallest power of 16 is 1: 0x59 Subtract 9 * 1 from 9 = 0 Convert hex to binary by inspection = Glenn Stevenson CSIS 113A MSJC
46
Glenn Stevenson CSIS 113A MSJC
Binary Numbers V An easier way to convert In Windows there is a calculator application (usually in the accessories group) Make certain that the scientific option is selected under the view menu Use the Hex, Oct, Dec and Bin radio buttons to convert numbers You’re probably now wondering why do I need to know this stuff??? C++, like it predecessor C, can do low-level programming You can “bit-twiddle” which is frequently necessary when dealing with hardware and systems programming When examining memory the addresses and values are normally displayed in hex Glenn Stevenson CSIS 113A MSJC
47
Glenn Stevenson CSIS 113A MSJC
Binary Numbers VI How can signed binary integers be stored? One scheme is called sign-magnitude method Give up a bit to represent sign (0 = positive) Remaining bits represent magnitude = - ( ) = -53 Not generally used because of the two-zeros problem = = -0 Glenn Stevenson CSIS 113A MSJC
48
Glenn Stevenson CSIS 113A MSJC
Binary Numbers VII One’s complement MSB [most-significant-bit] is used for sign bit If it is set, then one's complement is used to calculate the magnitude of negative number One’s complement: Reverse every bit (0 1 and 1 0) Also called complement Interpret result as an unsigned number Place minus sign in front of answer Still results in two zeros 0000 – 0000 = +0 1111 – 1111 = -0 Glenn Stevenson CSIS 113A MSJC
49
Glenn Stevenson CSIS 113A MSJC
Binary Numbers VII Two's complement results in one zero MSB [most-significant-bit] is used for sign bit If it is set, then two's complement is used to calculate the magnitude of negative number Two's complement: Reverse every bit [simple, or one's complement] Add one to the result Interpret result as an unsigned number Place minus sign in front of answer Glenn Stevenson CSIS 113A MSJC
50
Glenn Stevenson CSIS 113A MSJC
Binary Numbers VIII Wait a minute, how do I add 1 in binary? 1 + 1 = 0 carry 1 So Glenn Stevenson CSIS 113A MSJC
51
Glenn Stevenson CSIS 113A MSJC
Binary Numbers IX Wait a minute, how do I add 1 in binary? 1 + 1 = 0 carry 1 So Glenn Stevenson CSIS 113A MSJC
52
Glenn Stevenson CSIS 113A MSJC
Binary Numbers X Signed binary to decimal examples = + 3 MSB is clear - treat as positive unsigned = ??? MSB set - negative-perform two's complement 1. Reverse all of the bits : 2. Add one to result : 3. Interpret result : = 125 4. Add minus sign : Glenn Stevenson CSIS 113A MSJC
53
Glenn Stevenson CSIS 113A MSJC
Binary Numbers XI How to convert negative decimal numbers 1. Convert absolute value to binary 2. Perform two's complement on result Example: convert -59 to binary 1. Binary magnitude (59) 2. Perform two's complement Glenn Stevenson CSIS 113A MSJC
54
Glenn Stevenson CSIS 113A MSJC
Integral Number Types C++ Built-in Integral types char, unsigned char, and signed char short and unsigned short int and unsigned int (or unsigned) long, unsigned long In this course we will use int primarily On our 32-bit machines it takes 32-bits or 4 bytes to store an int Range -2,147,483,648 to 2,147,483,647 climits header defines limits Glenn Stevenson CSIS 113A MSJC
55
Glenn Stevenson CSIS 113A MSJC
The int data type I "Basic" integer is a signed whole number Size depends upon underlying platform On 16-bit systems - 16-bit int Today, almost all systems are 32 bit, tomorrow 64? Integer modifiers include: long [at least 32 bits, never smaller than int] short [at least 16 bits, never larger than int] unsigned [only positive numbers] Use of modifiers implicitly assumes type int e.g. long x; is equivalent to long int x; char one byte – may be signed do or unsigned Glenn Stevenson CSIS 113A MSJC
56
Glenn Stevenson CSIS 113A MSJC
int data type II How is an int stored in my computer It depends on your processor Intel processors use “Little Endian” Two byte words stored least significant word first with each word stored least significant byte first So 0x608bfa05 would be stored in memory as 05 fa 8b 60 Many other processors use “Big Endian” Words and bytes are stored most significant word and byte first So 0x608bfa05 would be stored in memory as 60 8b fa 05 If you use a memory dump to debug, this is what you will see Glenn Stevenson CSIS 113A MSJC
57
Glenn Stevenson CSIS 113A MSJC
The sizeof operator C++ mandates size "relationships" How can you find actual size of object? Use the sizeof operator (note operator - not a function) Returns size in "bytes" [usually 8 or 16 bits per byte – implementation dependent] cout << "sizeof 123 = " << sizeof 123; cout << "sizeof a = " << sizeof a; Parentheses required when using a type-name cout << "sizeof (int) = " << sizeof (int); Glenn Stevenson CSIS 113A MSJC
58
Floating Point Number Types
C++ Built-in Floating-point types float double long double In this course we will primarily use double On our 32-bit machines it takes 128 bits or 8 bytes to store a double Range e-308 to e+308 Precision 15 digits cfloat header defines limits Glenn Stevenson CSIS 113A MSJC
59
Glenn Stevenson CSIS 113A MSJC
Scientific Notation Also sometimes called Exponential Notation Usually used to express very large or very small numbers speed of light in a vacuum = 2.99 x 108 meters/sec Distance to Alpha Centauri = x 1012 miles Size of a hydrogen atom ≈ meters Mass of an electron = 9.11 x kg Number of atoms in the entire universe ≈ 1080 Expressed by a sign followed by a single digit followed by a decimal fraction followed by a power of ten The single digit plus the fraction is called the mantissa The power of ten is called the exponent Glenn Stevenson CSIS 113A MSJC
60
Scientific Notation II
So (7 5/16) is We can write this as x 22 In this case the sign is positive the mantissa is the exponent is 2 Glenn Stevenson CSIS 113A MSJC
61
Scientific Notation III
(3/16) is or 1.1 x 2-3 In this case the sign is positive the mantissa is 1.1 the exponent is -3 Glenn Stevenson CSIS 113A MSJC
62
Scientific Notation IV
And is or x 25 In this case the sign is negative the mantissa is the exponent is 5 Glenn Stevenson CSIS 113A MSJC
63
Glenn Stevenson CSIS 113A MSJC
Scientific Notation V What about 1.1? … 0.1 cannot be exactly represented as a binary fraction This is similar to 1/3 not being able to be exactly represented as a decimal fraction: … This is referred to as representational error Glenn Stevenson CSIS 113A MSJC
64
Scientific Notation VI
So how do we store these numbers in our computer? There are several conventions Most common is IEEE (Institute of Electrical and Electronics Engineers) standard Real*4 sign bit + 8-bit exponent + 23 bit mantissa Real*8 sign bit + 11-bit exponent + 52 bit mantissa Real*10 sign bit + 15-bit exponent + 64 bit mantissa Real*4 Real*8 Real*10 Precision (min) 6 digits 15 digits 18 digits Max Exponent 38 308 4932 Min Exponent -37 -307 -4931 Glenn Stevenson CSIS 113A MSJC
65
Glenn Stevenson CSIS 113A MSJC
Arithmetic Operators Operator Meaning + Add - Subtract * Multiply / Divide % Modulous int x = 3, y = 0; y = x + 6; y = x – 2; y = x * 2 y = 6 / x; Y = 6 % 3; 10 % 3 results in 1 Because 10 / 3 = 3 with a remainder of % 7 results in 5 Because 12 / 7 = 1 with a remainder of 5 20% 5 results in 0 Because 20 / 5 = 4 with a remainder of 0 Glenn Stevenson CSIS 113A MSJC
66
Glenn Stevenson CSIS 113A MSJC
Shortcut Notation int x = 4; Equivalent Value x+=5; x = x + 5 9 x-=1; x = x -1; 3 x*=5; x = x * 5; 20 x/=2 x = x / 2 4 x%=3 x = x % 3 1 Glenn Stevenson CSIS 113A MSJC
67
Glenn Stevenson CSIS 113A MSJC
Escape Characters A character pair that you can put into a string to perform an action. \n Newline \r Move the cursor back to the beginning of the line \t Insert a tab \\ Insert a single backslash \’ Single quote /” Double quote Below are not commonly used \v Vertical tab \b backspace \f Form feed \? Questions mark cout<<“hello\n”; cout<<“hello” << endl; Glenn Stevenson CSIS 113A MSJC
68
Glenn Stevenson CSIS 113A MSJC
Constants A read only variable It cannot be changed programmatically Example: PI Use const keyword const double PI = ; By convention const variables should be ALL CAPS Glenn Stevenson CSIS 113A MSJC
69
Glenn Stevenson CSIS 113A MSJC
C Typecasting Used to intentionally convert numbers From one type to another Can store small value in a larger bucket Cannot store larger value in smaller bucket Possible loss of data int x = 0; double z = ; x = z; // x now holds 33. Value is truncated & compiler // warning possible compiler error x = (int) z; //Temporarily converts z to an int. Still truncates but // no error or warning x = static_cast<int> z ; // c++ cast covered later Glenn Stevenson CSIS 113A MSJC
70
Glenn Stevenson CSIS 113A MSJC
Shorthand operators Called unary operators They operate on a single variable! ++ // increments a variable by one -- // decrements a variable by one int x = 3; int y = 2; x++; // x is now 4 y--; // y is now 1 Glenn Stevenson CSIS 113A MSJC
71
Post & Pre Increment/ Decrement
Can apply shorthand operators 2 ways Before variable ++x After Variable x++ Whats the difference? Consider: int x = 2; int y = 0; y = 1 * x++; // What does y equal here? y = 1 * ++x; // Now what does y equal Glenn Stevenson CSIS 113A MSJC
72
Glenn Stevenson CSIS 113A MSJC
Coding Style You should adopt a coding style that makes your code readable. Typically, you should indent whenever a block of code starts. and move it back when the block ends. How far you indent depends on your preference. I prefer 3 spaces. Some people like to do a tab, and still others like 4 spaces. Whatever you decide, be consistent. Int main() { cout << “Hello World” << endl; // Notice indent } Glenn Stevenson CSIS 113A MSJC
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.