[pdf] C++ basic concepts for beginners pdf download

C++ basic concepts for beginners pdf download

C++ (Basics)

In this blog , I've provided the pdf of C++ basics concept. I've also explain the c++ basic in the blog. This complete cource diveded into 5 modules

***Syllabus Covered***

*Module 1 (Basics and Control Structures)* 

*Module 2 (Arrays and Strings)*

*Module 3 (Pointers and Objects)* 

*Module 4 (Vector and Pair)*

*Module 5 (Stacks and Queues)*

*Module 6 (Sets and Maps)*


C++ group study starting from 1 august 

The above mentioned 6 modules will be covered



Module 1 (Basics and Control Structures)


*1.Writing first C++ program*

*2.C++ Data Types*

*3.Basic Input/Output*

*4.What is include and header files?*

*5.bits/stdc++.h header*

*6.What are namespaces?*

*7.cout << endl vs cout << “ ” in C++*

*8.Response on exceeding valid range of data types*


join the telegram group for constant updates

Code  corner

Output:

Basic syntax:-

cout<<variable_name;
cout<<"message";

cout is an object of class ostream
<< is called insertion or put to operator
(good to know but no need to understand the concept now)

First c++ program:


#include<iostream>
using namespace std;
int main(){
 cout<<"Hello world";
}


•#include is a preprocessor directive,
• iostream is a header file that contains declaration about cin,cout,>>
and <<.
•Without including this header file compiler won’t recognize
•using namespace std
•namespace is collection of identifiers(identifier is a name used to
identify a variable)
•std is namespace to which all the C++ identifiers belong to

Commenting

There are two ways to comment in c++ program:

int main(){

 cout<<"Hello world"; //this is a single line comment

 /* this

 is a

 multiline

 comment*/

}


Input

Basic syntax:

cin>>variable_name;

:cin is an object of class istream.

Example:

int main(){

 int a;

 cout<<"Enter a number";

 cin>>a;

 cout<<"You entered :"<<a;

}

Output:

Enter a number:5

You entered : 5


Printing in new line

Two ways to print in new line:

 "\n" //it is a character

endl //it is a function

Using "\n"

int main(){

 cout<<"Hello world\n";

 cout<<"How are you?";

}


Using endl

int main(){

 cout<<"Hello world"<<endl;

 cout<<"How are you?";

}

Output:

Hello world

How are you?


Variables and Datatypes

Variables are the names you give to computer memory locations which are

used to store values in a computer program

Rules for declaring variables:

 The first character in the variable name must be an alphabet or

underscore ( _ ).

 No commas or blanks are allowed within a variable name.

 No special symbol other than an underscore (as in gross_sal) can be

used in a variable name.

Ex: first_name,name1,Name etc.

Datatypes

All variables use data-type during declaration to restrict the type of data to

be stored.

Following are the datatypes used in C++.(primitive or fundamental)

 Integer int

 Character char

 Boolean bool

 Floating Point float

 Double Floating Point double

 Valueless or Void void


Datatypes modifier

 Signed

 Unsigned

 Short 

 Long

Range and size of datatypes:

•Integer: Keyword used for integer data types is int. Integers typically requires 4

bytes of memory space and ranges from -2147483648 to 2147483647.

•Character: Character data type is used for storing characters. Keyword used for

character data type is char. Characters typically requires 1 byte of memory

space and ranges from -128 to 127 or 0 to 255.

•Boolean: Boolean data type is used for storing boolean or logical values. A

boolean variable can store either true or false. Keyword used for boolean data type is bool.

•Floating Point: Floating Point data type is used for storing single precisionfloating point values or decimal values. Keyword used for floating point data typeis float. Float variables typically requires 4 byte of memory space.

•Double Floating Point: Double Floating Point data type is used for storing

double precision floating point values or decimal values. Keyword used for

double floating point data type is double. Double variables typically requires 8

byte of memory space.

void: Void means without any value. void datatype represents a valueless entity.

Void data type is used for those function which does not returns a value.

sizeof()

It returns size of datatype in bytes.

int main(){

 int a;

 char c;

 float f;

 double d;

 cout<<"char "<<sizeof(c)<<endl;

 cout<<"int "<<sizeof(a)<<endl;

 cout<<"float "<<sizeof(f)<<endl;

 cout<<"double "<<sizeof(d)<<endl;

}

Output:

Char 1

Int 4

Float 4

Double 8


Type conversion

Converting one datatype to another.

 Implicit type conversion

o Compiler converts the datatype to higher datatype

bool -> char -> short int -> int ->

unsigned int -> long -> unsigned ->

long long -> float -> double -> long double

 Explicit type casting

o It is done by using cast operator


Decision control instructions

 If

 If else

 Conditional or ternary operator

 Switch case


if statement


if(condition)

 statement;

 or

if(condition){

 statements;

 statements;

 }


If-else statements

if(condition)

 statement;

 else

 statement;

 or

 if(condition){

 statement;

 statement;

 }

 else{

 statement;

 statement;

 }

Conditional operator

condition?if true do this:else do this;

Switch case

switch(n){

 case 1: do this;

 break;

 case 2: do this;

 break;

 default:do this;

 }

Jump sttements:

Break transfers control outside the loop or switch case

Continue continues with the next iteration and skips rest instruction in lloop

goto transfer control to specified label

Increment and decrement operator

“++” is called increment operator it is a unary operator(requires only one

operand)

“--” is called decrement operator

 ++a is called preincrement

 it first increments and then implements

 a++ is called postincrement

 it first implements and then increments

 --a is called predecrement

 it first decrements and then implements

 a-- is called postdecrement

 it first implements and then decrements

++a increases the value of a by 1.

--a decreases the value of a by 1.

Loop

Loops are used to execute instructions repeatedly

Types of loops

 while

 do while

 for

while loop

Basic structure of while loop

initialize loop counter

 while(test loop counter using condition){

 statement

 or

 statements

 }

loop continues to execute instruction while the condition is true.

While loop is entry controlled loop.


do while loop

do{

 statement;

 or

 statements;

 increment counter;

 }while(condition);

It is an exit controlled loop.

It will execute the statement once even if the condition is false


For loop

for(initialize counter;test counter;increment counter){

 statement;

 or

 statements;

 }

It is entry controlled loop.

It is the most used loop.

[Read Online pdf here]

You can also download the note in pdf file

 Download text in pdf : Download pdf text

Also C programming notes download pdf :

Download here

C and c++ ebooks pdf download :Download pdf







1 Comments

Post a Comment

Previous Post Next Post