2. CONTENTS OF THIS COURSE
Here’s what you’ll find in this LECTURE1:
Functions
Data type.
Numeral System.
Variables.
Visualize code using Visualizer.
5. Functions
• You can think of function as a black box take an input and
produce an output and it’s not important to know what is
the algorithm inside of it , just enough to know how you can
use and what is their function.
Hello,World
7. Data types
• Fixed values such as numbers, letters, and strings are called
“constants”
• String constants use single quotes (') or double quotes (")
8. Data types
• Fixed values such as numbers, letters, and strings are called
“constants”
• String constants use single quotes (') or double quotes (")
9. Data types
• Numerical Data int, float, double.
• Textual Data string, char.
• Bolean Data true, false.
10. Some common Compiler errors
• Forgetting the semicolon ;
• Forgetting to one the curly braces of the main function { }
• Forgetting the “ “ in a string.
11. Some common Compiler errors
performs calculations
a billion calculations per second! two operations in same
time light travels 1 foot.
Remembers results
100s of gigabytes of storage!
typical machine could hold 1.5M books of standard size
13. Variables
• You can think of variable as a little box or a container to
store data in the memory of the computer and later
retrieve the data using the variable “name”
• Programmers get to choose the names of the variables
• You can change the contents of a variable in a later
statement
15. Rules for naming variables in C++
The first character of the name must be a letter or an underscore.
Only letters, digits, or underscores can follow the first letter. Blank
spaces aren’t allowed; separate words in a multiple-word identifier
are indicated by capitalizing the first letter of one or more of the
words. (Although underscores can also be used for this purpose,
they are increasingly being used only for compiler-dependent
identifiers.)
An identifier name can’t be one of the keywords listed in Table 1.1.
(A keyword is a word the language sets aside for a special purpose
and can be used only in a specified manner. 4 )
The maximum number of characters in an identifier is 1024.
23. Arian 5 the worst bug disaster
On June 4th, 1996, the very first Ariane 5 rocket ignited its
engines and began speeding away from the coast of French
Guiana. 37 seconds later, the rocket flipped 90 degrees in
the wrong direction, and less than two seconds later,
aerodynamic forces ripped the boosters apart from the
main stage at a height of 4km.
24. Arian 5 the worst bug disaster
On June 4th, 1996, the very first Ariane 5 rocket ignited its
engines and began speeding away from the coast of French
Guiana. 37 seconds later, the rocket flipped 90 degrees in
the wrong direction, and less than two seconds later,
aerodynamic forces ripped the boosters apart from the
main stage at a height of 4km.
26. Comments in C++
Comments in C++ begin with // character and continue to the end of the line.
Because comments do not execute, when you run a program you will not see
any indication of the comment there. Comments are in the source code for
humans to read, not for computers to execute.
31. User Input
C++ has an input function which lets you ask
a user for some text input
32. Input / Output in C++
cout (Console Output)
cin (Console Input)
33. Conditions
C++ uses boolean logic to evaluate conditions. The boolean
values True and False are returned when an expression is
compared or evaluated.
35. Conditions
C++ uses boolean logic to evaluate conditions. The boolean
values True and False are returned when an expression is
compared or evaluated.
36. Conditions
C++ uses boolean logic to evaluate conditions. The boolean
values True and False are returned when an expression is
compared or evaluated.
37. Conditions-Logic Gates
A Logic gate is a kind of the basic building block of a digital
circuit having two inputs and one output. ... Logic gates are
used to carry out the logical operations on single or
multiple binary inputs and result in one binary output. In
simple words, logic gates are the electronic circuits in a
digital system.
48. Data Structures
Every child knows that one can – at least beyond a certain
number – find things much easier if one keeps order. We
humans understand by keeping things in order that we
separate the things that we possess into categories and
assign fixed locations to these categories that we can
remember.
We may simply throw socks into a drawer, but for other things
like DVDs it is best to sort them beyond a certain number so
that we can quickly find every DVD.
62. Pointers
A pointer is a data item whose:
Value is a memory address.
Type describes the data located at that memory address.
Pointers make a computer environment more like the real
world!
63. Pointers
Pointers provide an alternative way to pass data between
function.
When we pass data by value in a function we pass a copy of
the data.
If we use pointers instead, we have the power to pass the
actual variable itself.
That means that a change that is made in one function can
impact what happens in a different function.
64. Pass by Reference Vs by Value
Passing by Reference affects the variable outside the
function’s scope.
Passing by reference doesn’t change anything outside the
function.
70. Dynamic Memory allocation
We Get this dynamically allocated memory by making
call to the c standard library function malloc() passing
as its parameter the number of bytes
Requested.
After obtaining memory for you(if it can), malloc will
return ap pointer to that memory.
What if malloc() can’t give you memory? It will hand you
back.
72. Dynamic Memory allocation
Here is the trouble: Dynamically- allocated memory is not
automatically returned to the system for later use, when function
in which it’s created finishes executed.
Failing to return memory back to the system when you’re
finished with it result in a memory leak, which can compromise
your system’s performance.
When you finish working with dynamically-allocated memory
you must free() it.