Professional Documents
Culture Documents
// A comment
// Created by Ephraim on 2015
<< Put into
cout << "God is love";
C++ A programming language.
Used from mars to the depths of the ocean.
Adobe/Autodesk uses it to create its products too.
Comment
Things which describe what the code says
Only for ourselves and fellow programmers
Computers do not even glace at it.
Compile time error
Errors found during compile time. Missing semicolons, undefined 'cout' etc.
Easier to correct than link time/run time errors.
cout Pronunced see-out. Stands for character output stream.
By default, it refers to the monitor.
Executable
This is what the computer actually executes
a.cpp --> a.obj --> a.exe
Function
Takes in something and gives an output.
In case of the main function, it is where the cpp program starts.
Header
Contains definitions of terms written by others so that we can use them.
IDE
Nice UI for writing code, debugging and compiling.
It automatically colour codes keywords, comments etc.
Library - code by others which can be ascessed by including it in #include
Linker
Links translation units to output an exe
a.obj + iostream.obj --> |Linker| --> a.exe
main()
This is where execution of a program starts.
It usually has an int datatype, with 0 indicating sucess and any other number fa
ilure
Object code
The code produced after compilation
a.cpp --> |Compiler| --> a.obj
.obj is not portable, so is .exe, not portable.
Output
What is displayed(usually on a screen)
Program
Written statements conveying the computer "what we want the computer to do".
Source code
Plain text of the program. Has the file extension .cpp (for c++)
Statement
A part of a program that specifies an action but is not an include or other preprocessor directive.
// Chapter 3 Objects Types and Values
Assigment '='
Assigning a value to an object. The object must already have an value.
Initilization also uses he same operator.
cin
Character input stream. cin >> a;
Usually the keyboard.
Concatenation
Joining two strings
str1 = "alpha"; str2 = "beta"; cout << str1 + str2; //alphabeta
Conversion
Converting from one data type to other.
May be explict or implict.
int a = 5; cout << (char)a;
cout << 5 / 5.0; // 5 is converted to double implictly
Declaration
A statement which gives name to an object.
int a;
Decrement
--a; // decreases a by one
Note that a-=2 decreases a by 2.
Definition
A definition is a declaration that sets aside memory for an object.
Increment
++a; // Increases a by one
Note that a+=2 increases a by 2;
Initilization
Gives a value to a variable such that it did not have a previous(even garbage) v
alue.
int a = 5;
Note that it has the datatype mentioned.
Name
Name of a variable. Used to refer to its vale.
Narrowing
Unsafe data type conversion where values get truncated
They put a value into an object that may be too small (
narrow
Object
Place in memory with a type which says what can be put into it.
Operation
) to hold it.
sort() - Defined in std lib facilities, takes a vector in its argument list and
sorts it
Switch statement - Compares a variable with a set of constants(case labels), exe
cuting statements for each case
Vector - A collection of elements with same data type. Unlike arrays, its number
of elements need not be specified at the start. They can be ascessed with an in
dex.
Statement - Anything that ends with a ;
while statement - a kind of loop where the loop variable is declared outside, an
d the increment of the loop varible is done inside. The loop continues as long a
s the control variable satisfies a condition
ch5 Errors
Argument error - When calling a function, bad arguments are given
Example - Negative width
Assertion - A statement that asserts an invariant
Catch - The process of catcing something thrown from a try block
In absence of a catcher for a throw the program terminates
Compile time error - Includes Type and syntax errors. These are found at compile
time by the
compiler(quicker to find) and are generally easier to fix.
Container - Collections of data (An object that holds other objects)
A vector is a container
Debugging - The process of removing bugs (not random, but by understanding how p
rogram works)
Error - A mismatch between what the user wants the program to do and what the pr
ogram really does
Execption - The object which is thrown by using throw and caught using catch. It
is used to indicate errors.
Invariant - A condition that must be true at that point in time of the program
Link time error - Errors found at link time. Takes more time to find than compil
e time errors. An example would be different datatypes for a same function in di
fferent translation units
Logic error - An error purely in logic of the programmer. A computer is a fast m
oron. Arises due to implict data type converion (converting temperatures 9/5, re
sults in 1 not 1.8), wrong formulas etc.
Post condition - A condition that must hold true upon end of a function or loop
Pre condition - A condition that must hold true at the start of a function or lo
op
Range error : Referring to anything outside [0, v.size()). Commonly occurs as [0
, v.size()]
Requirement - A descripting of the pre conditions of a function
Run time errors - Errors found at run-time, such as divide by zero. They are det
ected by computer, library or user code.
Function Definition : Allocates memory to the function. Must contain the stateme
nts which will be executed when the function is called
Global scope : The scope which is not nested inside any other scope. Every other
scope is nested inside the global scope. Any object in the global scope can be
used by anyone.
Header file : file containing declarations to be shared between programs. A sin
gle header file contains similiraly logical declarations.
Initializer : THe initial value r body of function. Use {}
Local scope : Between braces of a block or function
Namespace : A named scope to organize classes,functions, types etc
Namespace scope : A scope nested in a global scope or other namespace
Nested block : A block nested inside a if-else statement etc. Blocks within bloc
ks and within other functions
Parameter : Formal arguments, when called, the parameters get initialised with t
he actual values
Pass by const reference - WHere, instead of the value of an object, the location
of the object is sent. Futhermore, the location's value is unchangeable
Pass by value : Sends the value to the function, the value is the initilazer to
the formal argument
Pass by reference : Send the location of object instead of the value. Such a met
hod implies that the value in the location will be modified by the function.
Recursicion : When a function calls itself directly or indirectly when a functio
n calls another function which calls the original function.
Return : The first word in a function definition/declaration is the return data
type. The keyword return should be followed by the object to be returned(unless
its a void) followed by a semicolon to return something from a fuction.
Return value : THe value of the returned data type
Scope : A region in program text.
Technicalities : The grammar of language such as the syntax etc
Undeclared identifier - Using a name before it is declared
using : Refer to this name of this namespace when I refer to the name unqualifie
d
Unless the name is locally present.
using namespace : When I use an unqualified name refer the name in this namespac
e unless that name is already locally present.