INTRO TO
PROGRAMMING
By PEC ACM
TABLE OF CONTENTS
1 < session_start >
< compilers_and_ide >
< data_types >
< operators >
< conditional_statements >
< loops >
2
< doubts >
WHAT AND WHY?
Programming is the process of writing
instructions for a computer to perform
tasks, or solve problems.
Problem Solving
Automation
Creativity
Career opportunities
How Compilers Work?
COMPILER INTERPRETER
It takes a single line of code or instruction a
It takes an entire program at a time
time
It doesn’t produce any intermediate object
It generates intermediate object code
code
Compilation and executions takes place
Compilation is done before execution
simultaneously
Comparatively faster Slower
Display all errors after compilation, all at the
Displays error of each line one by one
same time
Difficult Comparatively easier
Languages : C, C++, C#, Scala, Typescript Languages : PHP, Perl, Python, Ruby
IDE
An IDE (Integrated Development Environment)
is software that helps programmers write,
run, and fix code easily. Example: VS Code.
Minimizes error
Ease of use
Efficiency
WHY C++?
Develops a strong foundational understanding
of computer science and programming principles
Deep Understanding of Computer Architecture
(using pointers)
Performance and Efficiency
Introduction to Multiple Programming Paradigms
C++ BASIC SYNTAX
same code o_o
Data Types in C++
Integer Float Character
Numbers with decimal point
Numbers like {1, 2, 3, 0, -1, -2, like {1.25, 3.14} Single Characters enclosed in
3....} Floats can hold up to 7 decimal single quotes like {’A’, ‘b’, ‘&’}
digits
Keyword: int Keyword: float Keyword: char
Data Types in C++
Double Boolean
Stores either True or False value.
Decimal point numbers (like float).
True =1
Double can hold up to 15 decimal digits.
False=0
Keyword = double Keyword: bool
Size of Data Types
char 1 byte
int 4 bytes
float 4 bytes
double 8 bytes
bool 1 byte
Find the output?
Answer:
Error :
The entry point of the program must be named
''main'', not ''Main''.
Find the output?
Answer:
Error :
This tries to assign c to the result of a + b,
which is incorrect because you cannot assign
a value to an arithmetic expression.
Find the output?
Answer:
1
Any non-zero value is considered true
(represented as 1 when output)
Quick Quiz!
Type of variable that stores whole number without decimal.
1) long
2) int
3) string
4) float
Type of variable that stores upto 7
decimal digits?
1) long
2) int
3) string
4) float
Type of variable that stores True or False value.
1) long
2) int
3) boolean
4) float
The value 132.54 can be represented using which
data type?
a) double
b) void
c) int
d) bool
Operators in C++
1) Arithmetic operators
These include : +, -, * , /, %
OUTPUT :
a + b = 11
a-b=5
a/b=2
a%b=2
2) Relation Operators
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal to
OUTPUT :
a == b is 0
a > b is 1
a >= b is 1
a < b is 0
a <= b is 0
a != b is 1
3) Logical Operators
&& - logical AND
|| - logical OR
! - Logical NOT
OUTPUT :
a && b is 1
a || b is 1
!b is 0
4) Assignment operators
Increment and Decrement Operators
INCREMENT ( ++ ) DECREMENT ( - - )
The increment operator increases the The decrement operator decreases the
value stored by the variable by 1. value stored by the variable by 1.
Pre - Increment vs Post - Increment
PRE - INCREMENT POST - INCREMENT
Increment the value of a variable before Value is first incremented and then used
using it in an expression inside the expression.
OUTPUT :
20
40
20
40
Guess the output?
OUTPUT :
5/9 = 0
(f - 32 ) * 0 = 0
Guess the output?
OUTPUT :
-40
f - 32 = -72.0
-72 * 5 = -360.0
-360 / 9 = -40
Conditional Statements
if
if - else
if - else if - else
switch case
CONDITIONAL STATEMENTS
Conditionals let a
program make decisions.
If something is true, the
program does one thing.
If it’s false, it can do
something else.
SYNTAX FOR CONDITIONAL STATEMENTS
1 IF Statement
Sample Code
// Output : Inside if statement
SYNTAX FOR CONDITIONAL STATEMENTS
2 IF - Else Statement
Sample Code
// Output : B is greater than A
SYNTAX FOR CONDITIONAL STATEMENTS
3 IF - Else if - Else Statement Sample Code
// Output : Positive
FIND THE OUTPUT ?
OUTPUT
Inside if 15
EXPLANATION
The condition of ( x <= 15 ) is satisfied so the
‘else if’ condition is not being checked
FIND THE ANSWER?
For what values of the x, the 'if-statement' block will not
be executed ?
OUTPUT
0
EXPLANATION
( 1 - 0 ) == ( 1 + 0 )
FIND THE OUTPUT?
OPTIONS
OUTPUT
B) Bye
EXPLANATION
++ a * 5 is equivalent to (a + 1)*5
FIND THE OUTPUT?
OUTPUT
EXPLANATION
x XOR y = 0 ( false ) ,when ( x = y ) ;
Therefore ! ( x ^ y ) = true