Basics of Programming in C++
Basics of Programming in C++
LECTURE : 2
Basics of Programming C++.
TABLE OF CONTENTS
03 Condition Statements
04 Loops
05 Operators
06 Arrays and Problems Solving
FIRST PROGRAM IN C++
#include<bits/stdc++.h>
using namespace std;
Header Files
int main() {
cout<<“Hello World”;
return 0; Main() Function
}
1.) int
2.) long long int
3.) float
4.) double
5.) bool (Boolean)
6.) char
Syntax of a Variable :
DataType varname;
Ex : int data;
String String str = “Hello”;
If else are two conditional statements, which are generally used when we want to
run the code based on some condition.
For Loop
Syntax :
for(initialization;condition;updation){
Ex:
for(int i=0;i<10;i++){
cout<<“hello”;
}
For loops are used to repeat the execution of the code, instead of repeating the code
again and again.
While Loop
Syntax :
while(condition){
Body;
}
Ex:
While(num<10)
{
cout<<num;
num+=1;
}
While loops are used when we don’t know the exact number of times the loop
should repeat.it repeats the statement or body till the condition is true.
Operators
And : &
or : |
xor : ^
Not : !
#include<bits/stdc++.h>
using namespace std;
int main() {
cout<<“Hello World”;
return 0;
Arrays can be defined
} as group or collection of elements of the same type.
Array elements are stored at contiguous memory locations.
Syntax for Array Declaration
Datatype arr_name[no. of elements];
Functions
Syntax :
Return-type name(arguments){
body;
}