Introduction to Programming-1
Introduction to Programming-1
INTRO TO
PROGRAMMING
WHAT AND WHY?
www.reallygreatsite.com
C++ BASIC SNYTAX
Data Types in C++
Integer Float Character
Numbers like 1, 2, Numbers with Single characters enclosed in
decimal points, like single quotes, like 'A', 'b'.
3,0,-1,-2,-3 etc.
1.25, 3.14. keyword = char
Keyword = int
Float can hold up to
7 decimal digits.
Consumes 4 bytes
for storage.
Keyword = float
Data Types in C++
Double Boolean
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:
Error :
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
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 : +, -, * , /, %
Increment Operator: ++
Decrement Operator: --
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
3) Assignment Operators
Fast Input/Output in C++
In competitive programming, it is important to read input as
fast as possible so we save valuable time.It is often
recommended to use scanf/printf instead of cin/cout for fast
input and output. However, you can still use cin/cout and
achieve the same speed as scanf/printf by including the
following two lines in your main() function:
ios_base::sync_with_stdio(false);
cin.tie(NULL);
Moreover, you can include the standard template library (STL)
with a single include:
#include <bits/stdc++.h>
For Loop
While Loop
Do-While Loop
Syntax for Loops
1) For Loop
SAMPLE CODE SNIPPET
OUTPUT :
1
2
3
4
.
.
100
Syntax for Loops
2) While Loop
SAMPLE CODE
OUTPUT :
1
2
3
4
.
.
100
SAMPLE CODE
Syntax for Loops
2) Do-While Loop
OUTPUT :
1
2
3
4
.
.
100
Guess the output?
OUTPUT :
-3
-2
-1
0
1
2
3
Find the output?
OUTPUT :
IF statement
IF - ELSE Statement
IF - ELSEIF - ELSE Statement
SWITCH CASE Statement
SYNTAX FOR CONDITIONAL STATEMENTS
1 IF Statement
Sample Code
Sample Code
// Output : b is bigger
SYNTAX FOR CONDITIONAL STATEMENTS
3 IF - Else if - Else Statement Sample Code
// Output : Positive
SYNTAX FOR CONDITIONAL STATEMENTS
4 Switch Case Sample Code
// Output : Choice is A
DIFFERENCE BETWEEN SWITCH AND IF ELSE IF
FIND THE OUTPUT ?
OUTPUT
Inside if 15
EXPLANATION
EXPLANATION
( 1 - 0 ) == ( 1 + 0 )
FIND THE OUTPUT?
OUTPUT
EXPLANATION
Switch Case without break
FIND THE OUTPUT?
OPTIONS
OUTPUT
B option
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
WHATSAPP GRP INSTAta