SlideShare a Scribd company logo
1 of 46
Presented By
,
SukhpreetSingh
INTRODUCTIONTOC++
HISTORYOF C++
C++ is a multi-paradigm programming language that
supports object oriented programming (OOP) created
by Bjarne Stroustrup in 1983 at Bell labs, C++ is an
extension of C programming and the programs written
in Clanguage can run in C++ compiler.
The development of C++ actually began four years
before its release, in 1979. It did not start with the
name C++. Its first name was Cwith classes.
In the late part of 1983, C with classes was first used for
AT&T’s internal programming needs. Its name was
changed to C++ later in the same year.
It is of course also used in a wide range of other
application domains, notable graphics programming. C++
supports inheritance through class derivation. Dynamic
binding is provided by Virtual class function.
DIFFERENCEBETWEENCANDC++
C C++
C is Procedural Language. C++ is non-Procedural i.e. Object
oriented Language.
Top down approach is used in
Program
Design.
Bottom up approach adopted in
Program
Design.
Multiple Declaration of global variables
are
allowed.
Multiple Declaration of global variables
are
not allowed.
C requires all the variables to be
defined at the starting of a scope.
C++ allows the declaration of
variable anywhere inthe scopei.e. at
timeof its Firstuse.
InC,malloc() andcalloc () Functions are
used for Memory Allocation and
free () function for memory
Deallocating.
In C++, new and delete operators
are used for Memory Allocating
and Deallocating.
USESOF C++ LANGUAGE
C++ is used by programmers to develop computer
software
It is used to create general systemsoftware
Used tobuild drivers for various computer devices
Software for servers and software for specific
applications
Used in the creation of video games.
ADVANTAGEOF C++
 C++ is relatively-lowlevel and is asystems programming
language.
 It has a large community.
 It has a relatively clear and mature standard.
 Modularity’
 Reusability andreadability
DISADVANTAGEOF C++
× Data is global or local.
× It emphasis on instructions bur not on data.
× It canbe generally heavy if not careful.
× Data is global and global datadoes not have security.
STANDARDLIBRARIES
The C++ Standard Library can be categories into two
parts:
The standard function library: This library consists of
general-purpose, stand-alone function that are not part of
any class. The function library is inherited fromC.
The object oriented class library: This is a collection of
classes and associated function.
Standard C++ library incorporates all the standard C
libraries also, with small additions and changes to support
type safety.
STRUCTUREOFC++
SIMPLEPROGRAMC++
#include<iostream.h>/*Header File*/
int main()/*Main Function*/
{
cout<<"n*HELLO*n";
/*Output Statements*/
}
C++ DATATYPES
Primary data type int, float, char, void
User defined data
type
structure, union, class, enumeration
Derived data type array, function, pointer, reference
C++ VARIABLESSCOPE
A scope is a region of the program and broadly
speaking there are three places, where variables can
be declared −
Inside a function or a block which is called local
variables,
In the definition of function parameters which is called
formal parameters.
Outside of all functions which is called global
variables.
LOCALVARIABLES
#include <iostream.h>
int main ()
{
int a, b;
int c;
a=10;
b=20;
c =a +b;
cout <<c;
return0;
}
Output = ?
Output = 30
// Local variable declaration
// actual initialization
GLOBALVARIABLES
#include<iostream.h>
// Global variable declaration:
Int g;
int main()
{
// Local variable declaration:
int a, b;
// actual initialization
a =10;
b =20;
g = a + b;
cout << g;
return0;
}
Output = ?
Output = 30
OPERATORS
• Arithmetic operators
• Relational operators
• Logical operators
• Bitwise operators
• Assignment operators
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
cout<<“enter the value for aand
b”;
cin>>a>>b;
c=a+b;
cout<<c;
c=a-b;
cout<<c;
c=a*b;
cout<<c;
c=a/b;
cout<<c;
c=a++;
cout<<“incrementation of a by
one”<<c;
c=a--;
cout<<”decrementationof a by
one”<<c);
}
ARITHMETICOPERATORS
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b; a=10;b=13;
if(a<b)
{ cout<<“a is less than b”; }
if(a>b)
{ cout<<”a is greater than b”; }
if(a<=b)
{ cout<<”ais less than or equal
to b”; }
if(a>=b)
{ cout<<“ais greater than or
equal to b”; }
if(a==b)
{ cout<<”a is equal to b”; }
if(a!=b)
{ cout<<”ais not equal tob”);
}
}
RELATIONALOPERATORS
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
a=12;
b=10;
if(a&&b)
{ cout<<”condition is true”; }
if(a||b)
{ cout<<“condition is true”; }
a=0;
b=10;
if(a&&b)
{ cout<<“condition is true”; }
else
cout<<“condition is not true”;
if(!(a&&b))
{ cout<<“condition is true”; } }
LOGICALOPERATORS
BITWISEOPERATOR
Bitwiseoperatorworksonbitsandperformbit-by-bitoperation.
P Q P&Q P|Q P^Q
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Assume if A=60; and B=13; nowin binary format they will
be as follows:
A=0011 1100 ---->Binary Number for 60
B=0000 1101 ---->Binary Number for 13
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
#include <iostream.h>
int main() {
int a=7; // a=111
int b =5; // b =101
cout <<"Bitwise Operatorsn";
cout <<"a&b =" << (a&b) <<"n";
cout <<"a| b =" << (a|b) <<"n";
cout <<"a^ b =" << (a^b) <<"n";
cout <<"~a=" << (~a) <<"n";
cout <<"~b=" << (~b) <<"n";
cout <<"a>>b =" << (a>>b) <<"n";
cout <<"a<<b =" << (a<<b) <<"n";
}
Bitwise
Operators a&b
=5
a| b=7
a^b=2
~a=-8
~b=-6
a>>b=0
a<<b=224
Output=?
Output
ASSIGNMENTOPERATOR
An assignment operator, in the context of the C
programming language, is a basic component denoted as
"=".
int x = 25;
x =50;
FUNCTIONS
Function is a set of statements to perform some task.
 Every C++ programhas at least one function, which is
main(), and all the most trivial programs can define
additional functions.
Syntax of Function
return-type function-name (parameters)
{
// function-body
}
DECLARING, DEFININGANDCALLINGFUNCTION
#include<iostream.h>
int sum (int x, int
y);
int main()
{
//declaring function
int a = 10;
int b = 20;
int c = sum (a,
b);
//calling function
cout << c;
}
int sum (int x, int
y)
{
//defining function
Output =
Outp
ut
?
= 30
CALLINGAFUNCTION
Functions are called by their names. If the function is
without argument, it can be called directly using its
name. But for functions with arguments, we have two
ways tocall them,
Call by V
alue
Call by Reference
CALLBYVALUE
#include<iostream.h>
voidswap(int x, int y); // functiondeclaration
int main()
{
int a =100;
int b=200;
cout << "Before swap, value of a :" <<a << endl;
cout << "Before swap, value of b :" <<b << endl;
swap(a,b); // calling afunction to swapthe values.
cout << "After swap, value of a :" <<a << endl;
cout <<"After swap, value of b :" <<b<< endl;
return 0; }
// local variable declaration:
OUTPUT
:
Beforeswap,valueofa:100
Beforeswap,valueofb:200
Afterswap,valueofa:200
Afterswap,valueofb:100
CALLBYREFERENCE
#include <iostream.h>
void swap(int &x, int &y); // function declaration
int main ()
{
int a = 100;
int b =200;
cout <<"Before swap, value of a :" <<a << endl;
cout << "Before swap, value of b :" << b << endl;
swap(a, b); // calling a functionto swapthe values using variable reference.*/
cout << "After swap, value of a :" << a << endl;
cout << "After swap, value of b :" << b << endl;
return 0;
}
// local variable declaration:
OUTPUT
:
Beforeswap,valueofa:100
Beforeswap,valueofb:200
Afterswap,valueofa:200
Afterswap,valueofb:100
ARRAYS
 Array is defined as a set of homogeneous data items. An Array
is a group of elements that share a common name that are
differentiated from one another by their positions within the
array.
 It is a data structure which allows a collective name to be given
to agroup of elements which all have the sametype.
Syntax
datatype arrayname[array size];
 The Array which is declared as above is called single-dimension
array
Example: float salary[10];
float 
salary 
[10] 
data type
array name
array size(integer)
Thesize of anarray mustbeaninteger constant and
the data type can be any valid C++ data type.
ARRAYINITIALIZATION
 In C++elements of an array can be initialized one by one or
using asingle statement
float balance[5]={1000.0, 2.0, 3.4,7.0, 50};
 The number of values between braces { } cannot be larger than
the number of elements that we declare for the array between
square brackets [ ].
C++ARRAYINDETAIL
CONCEPT DESCRIPTION
Multi-dimensional arrays C++supportsmultidimensionalarrays.Thesimplest
form of the multidimensional array is the
two- dimensional array.
Pointer to an array Youcangenerateapointertothefirstelementofan
arraybysimplyspecifyingthearrayname,withoutany
index.
Passing arrays to
functions
You can pass to the function a pointer to an
array by specifying the array's name
without an index.
Return array from
functions
C++ allows a function to return an array.
POINTERS
 Pointer is a user defined data type which creates special types
of variables which can hold the address of primitive data type
like char, int, float, double or user defined data type like
function, pointer etc. or derived data type like array, structure,
union, enum.
WhatAre Pointers?
 A pointer is a variable whose value is the address of another
variable. Like any variable or constant, you must declare a
pointer before you can work with it.
Syntax
datatype *var-name;
int *ip;
double*dp;
float *fp;
char *ch
// pointer toaninteger
// pointer toadouble
// pointer toafloat
// pointer tocharacter
USINGPOINTERSINC++
 Therearefewimportantoperations,whichwewill dowith the
pointers very frequently.
(a) wedefinea pointer variables
(b) assign the address of a variable to a pointer and
(c) finally access the value at the address available in the
pointer variable.
 This is done by using unary operator * that returns the value of
the variable located at the address specified by its operand.
C++ POINTERSINDETAIL
CONCEPT DESCRIPTION
C++ Null Pointers C++supportsnullpointer,whichisaconstantwitha value
of zero defined in several standard libraries.
C++ pointer arithmetic There are four arithmetic operators that can
be used on pointers: ++, --, +, -
C++ pointers vs. arrays Thereis acloserelationship between pointers andarrays.
Let us check how?
C++ array of pointers You can define arrays to hold a number of
pointers.
C++ pointer to pointer C++ allows you to have pointer on a pointer and so
on.
Passing pointers to functions Passing an argument by reference or by
address both enable the passed argument to
be changed in the calling function by the called
function.
Return pointer from functions C++ allows a function to return a pointer to local
C++ STRINGS
 The following declaration and initialization create a string
consisting of the word "Hello". To hold the null character at the
end of the array, the size of the character array containing the
string is one more than the number of characters in the word
"Hello.“
 Method1: char greeting[6] ={'H', 'e', 'l', 'l', 'o', '0'};
 Method2: char greeting[] ="Hello";
•
#include
<iostream.h> int
main ()
{
char greeting[6] ={'H', 'e', 'l', 'l', 'o', '0'};
cout <<"Greeting message: ";
cout <<greeting << endl;
return 0;
}
OUTPU
T
OUTPUT
Greetingmessage: Hello
Functions Purpose
strcpy(s1, s2); Copies string s2 into string s1.
strcat(s1, s2); Concatenatesstrings2ontotheendofstring s1.
strlen(s1); Returns the length of string s1.
strcmp(s1, s2); Returns0if s1ands2arethesame;lessthan0if s1<s2;
greater than 0 if s1>s2.
strchr(s1, ch); Returnsapointertothefirstoccurrenceofcharacterchinstring
s1.
strstr(s1, s2); Returnsapointertothefirstoccurrenceofstrings2in string s1.
#include<iostream>
#include<cstring>
int main() {
char str1[10] ="Hello";
char str2[10] ="World";
char str3[10];
int len;
strcpy( str3, str1); // copystr1intostr3
cout <<"strcpy( str3, str1) : " <<str3<< endl;
strcat( str1, str2); // concatenatesstr1 andstr2
cout <<"strcat( str1, str2): " <<str1<< endl;
len =strlen(str1); // total length of str1 after concatenation
cout <<"strlen(str1) : " <<len << endl;
return0;
}
FILEHANDLINGINC++
 File Handling concept in C++ language is used for store a data
permanently in computer. Using file handling we can store our
data in Secondary memory (Hard disk).
Whyuse FileHandling
For permanent storage.
The transfer of input - data or output - data fromone
computer to another can be easily done by using files.
 Forreadandwritefromafile youneedanotherstandardC++
library called fstream, which defines three new data types:
Datatype Description
ofstream This is used to create a file
and write data on files
ifstream This is used to read data from
files
fstream This is used to both read and
write data from/to files
HOWTOACHIEVEFILEHANDLING
For achieving file handling in C++we need follow following steps
 Naming a file
 Opening a file
 Reading data fromfile
 Writing data into file
 Closing a file
FUNCTIONSUSEINFILEHANDLING
Function Operation
open() To create a file
close() To close an existing file
get() Read a single character from a file
put() write a single character in file.
read() Read data from file
write() Write data into file.
FILEREADOPERATION
#include<conio.h>
#include<fstream.h>
int main()
{
char c,fname[10];
cout<<"Enter file name:";
cin>>fname;
ifstreamin(fname);
if(!in)
{
cout<<"FileDoes not Exist";
getch();
return0;
}
cout<<"nn";
while(in.eof()==0)
{
in.get(c);
cout<<c;
}
getch();
}
FILEWRITEOPERATION
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<fstream.h>
int main()
{ char c,fname[10];
ofstreamout;
cout<<"Enter File name:";
cin>>fname;
out.open(fname);
cout<<"Enter contents to store in file (Enter # at end):n";
while((c=getchar())!='#')
}
{ out<<c;
out.close();
getch();
return 0; }

More Related Content

Similar to CPP-overviews notes variable data types notes

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIADheeraj Kataria
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structuresPradipta Mishra
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures Pradipta Mishra
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And AnswerJagan Mohan Bishoyi
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operatorSAFFI Ud Din Ahmad
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 

Similar to CPP-overviews notes variable data types notes (20)

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
c++ referesher 1.pdf
c++ referesher 1.pdfc++ referesher 1.pdf
c++ referesher 1.pdf
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
 
C++ theory
C++ theoryC++ theory
C++ theory
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
C++ functions
C++ functionsC++ functions
C++ functions
 
C++ functions
C++ functionsC++ functions
C++ functions
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 

More from SukhpreetSingh519414

More from SukhpreetSingh519414 (8)

python full notes data types string and tuple
python full notes data types string and tuplepython full notes data types string and tuple
python full notes data types string and tuple
 
ppt notes python language operators and data
ppt notes python language operators and datappt notes python language operators and data
ppt notes python language operators and data
 
ppt python notes list tuple data types ope
ppt python notes list tuple data types opeppt python notes list tuple data types ope
ppt python notes list tuple data types ope
 
ppt notes for python language variable data types
ppt notes for python language variable data typesppt notes for python language variable data types
ppt notes for python language variable data types
 
C%20ARRAYS.pdf.pdf
C%20ARRAYS.pdf.pdfC%20ARRAYS.pdf.pdf
C%20ARRAYS.pdf.pdf
 
java exception.pptx
java exception.pptxjava exception.pptx
java exception.pptx
 
finap ppt conference.pptx
finap ppt conference.pptxfinap ppt conference.pptx
finap ppt conference.pptx
 
final security ppt.pptx
final security ppt.pptxfinal security ppt.pptx
final security ppt.pptx
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

CPP-overviews notes variable data types notes

  • 2. HISTORYOF C++ C++ is a multi-paradigm programming language that supports object oriented programming (OOP) created by Bjarne Stroustrup in 1983 at Bell labs, C++ is an extension of C programming and the programs written in Clanguage can run in C++ compiler. The development of C++ actually began four years before its release, in 1979. It did not start with the name C++. Its first name was Cwith classes.
  • 3. In the late part of 1983, C with classes was first used for AT&T’s internal programming needs. Its name was changed to C++ later in the same year. It is of course also used in a wide range of other application domains, notable graphics programming. C++ supports inheritance through class derivation. Dynamic binding is provided by Virtual class function.
  • 4. DIFFERENCEBETWEENCANDC++ C C++ C is Procedural Language. C++ is non-Procedural i.e. Object oriented Language. Top down approach is used in Program Design. Bottom up approach adopted in Program Design. Multiple Declaration of global variables are allowed. Multiple Declaration of global variables are not allowed. C requires all the variables to be defined at the starting of a scope. C++ allows the declaration of variable anywhere inthe scopei.e. at timeof its Firstuse. InC,malloc() andcalloc () Functions are used for Memory Allocation and free () function for memory Deallocating. In C++, new and delete operators are used for Memory Allocating and Deallocating.
  • 5. USESOF C++ LANGUAGE C++ is used by programmers to develop computer software It is used to create general systemsoftware Used tobuild drivers for various computer devices Software for servers and software for specific applications Used in the creation of video games.
  • 6. ADVANTAGEOF C++  C++ is relatively-lowlevel and is asystems programming language.  It has a large community.  It has a relatively clear and mature standard.  Modularity’  Reusability andreadability
  • 7. DISADVANTAGEOF C++ × Data is global or local. × It emphasis on instructions bur not on data. × It canbe generally heavy if not careful. × Data is global and global datadoes not have security.
  • 8. STANDARDLIBRARIES The C++ Standard Library can be categories into two parts: The standard function library: This library consists of general-purpose, stand-alone function that are not part of any class. The function library is inherited fromC. The object oriented class library: This is a collection of classes and associated function. Standard C++ library incorporates all the standard C libraries also, with small additions and changes to support type safety.
  • 10. SIMPLEPROGRAMC++ #include<iostream.h>/*Header File*/ int main()/*Main Function*/ { cout<<"n*HELLO*n"; /*Output Statements*/ }
  • 11. C++ DATATYPES Primary data type int, float, char, void User defined data type structure, union, class, enumeration Derived data type array, function, pointer, reference
  • 12. C++ VARIABLESSCOPE A scope is a region of the program and broadly speaking there are three places, where variables can be declared − Inside a function or a block which is called local variables, In the definition of function parameters which is called formal parameters. Outside of all functions which is called global variables.
  • 13. LOCALVARIABLES #include <iostream.h> int main () { int a, b; int c; a=10; b=20; c =a +b; cout <<c; return0; } Output = ? Output = 30 // Local variable declaration // actual initialization
  • 14. GLOBALVARIABLES #include<iostream.h> // Global variable declaration: Int g; int main() { // Local variable declaration: int a, b; // actual initialization a =10; b =20; g = a + b; cout << g; return0; } Output = ? Output = 30
  • 15. OPERATORS • Arithmetic operators • Relational operators • Logical operators • Bitwise operators • Assignment operators
  • 16. #include<iostream.h> #include<conio.h> void main() { int a,b,c; cout<<“enter the value for aand b”; cin>>a>>b; c=a+b; cout<<c; c=a-b; cout<<c; c=a*b; cout<<c; c=a/b; cout<<c; c=a++; cout<<“incrementation of a by one”<<c; c=a--; cout<<”decrementationof a by one”<<c); } ARITHMETICOPERATORS
  • 17. #include<iostream.h> #include<conio.h> void main() { int a,b; a=10;b=13; if(a<b) { cout<<“a is less than b”; } if(a>b) { cout<<”a is greater than b”; } if(a<=b) { cout<<”ais less than or equal to b”; } if(a>=b) { cout<<“ais greater than or equal to b”; } if(a==b) { cout<<”a is equal to b”; } if(a!=b) { cout<<”ais not equal tob”); } } RELATIONALOPERATORS
  • 18. #include<iostream.h> #include<conio.h> void main() { int a,b; a=12; b=10; if(a&&b) { cout<<”condition is true”; } if(a||b) { cout<<“condition is true”; } a=0; b=10; if(a&&b) { cout<<“condition is true”; } else cout<<“condition is not true”; if(!(a&&b)) { cout<<“condition is true”; } } LOGICALOPERATORS
  • 20. Assume if A=60; and B=13; nowin binary format they will be as follows: A=0011 1100 ---->Binary Number for 60 B=0000 1101 ---->Binary Number for 13 ----------------- A&B = 0000 1100 A|B = 0011 1101 A^B = 0011 0001 ~A = 1100 0011
  • 21. #include <iostream.h> int main() { int a=7; // a=111 int b =5; // b =101 cout <<"Bitwise Operatorsn"; cout <<"a&b =" << (a&b) <<"n"; cout <<"a| b =" << (a|b) <<"n"; cout <<"a^ b =" << (a^b) <<"n"; cout <<"~a=" << (~a) <<"n"; cout <<"~b=" << (~b) <<"n"; cout <<"a>>b =" << (a>>b) <<"n"; cout <<"a<<b =" << (a<<b) <<"n"; } Bitwise Operators a&b =5 a| b=7 a^b=2 ~a=-8 ~b=-6 a>>b=0 a<<b=224 Output=? Output
  • 22. ASSIGNMENTOPERATOR An assignment operator, in the context of the C programming language, is a basic component denoted as "=". int x = 25; x =50;
  • 23. FUNCTIONS Function is a set of statements to perform some task.  Every C++ programhas at least one function, which is main(), and all the most trivial programs can define additional functions. Syntax of Function return-type function-name (parameters) { // function-body }
  • 24. DECLARING, DEFININGANDCALLINGFUNCTION #include<iostream.h> int sum (int x, int y); int main() { //declaring function int a = 10; int b = 20; int c = sum (a, b); //calling function cout << c; } int sum (int x, int y) { //defining function Output = Outp ut ? = 30
  • 25. CALLINGAFUNCTION Functions are called by their names. If the function is without argument, it can be called directly using its name. But for functions with arguments, we have two ways tocall them, Call by V alue Call by Reference
  • 26. CALLBYVALUE #include<iostream.h> voidswap(int x, int y); // functiondeclaration int main() { int a =100; int b=200; cout << "Before swap, value of a :" <<a << endl; cout << "Before swap, value of b :" <<b << endl; swap(a,b); // calling afunction to swapthe values. cout << "After swap, value of a :" <<a << endl; cout <<"After swap, value of b :" <<b<< endl; return 0; } // local variable declaration: OUTPUT : Beforeswap,valueofa:100 Beforeswap,valueofb:200 Afterswap,valueofa:200 Afterswap,valueofb:100
  • 27. CALLBYREFERENCE #include <iostream.h> void swap(int &x, int &y); // function declaration int main () { int a = 100; int b =200; cout <<"Before swap, value of a :" <<a << endl; cout << "Before swap, value of b :" << b << endl; swap(a, b); // calling a functionto swapthe values using variable reference.*/ cout << "After swap, value of a :" << a << endl; cout << "After swap, value of b :" << b << endl; return 0; } // local variable declaration: OUTPUT : Beforeswap,valueofa:100 Beforeswap,valueofb:200 Afterswap,valueofa:200 Afterswap,valueofb:100
  • 28. ARRAYS  Array is defined as a set of homogeneous data items. An Array is a group of elements that share a common name that are differentiated from one another by their positions within the array.  It is a data structure which allows a collective name to be given to agroup of elements which all have the sametype. Syntax datatype arrayname[array size];  The Array which is declared as above is called single-dimension array
  • 29. Example: float salary[10]; float  salary  [10]  data type array name array size(integer) Thesize of anarray mustbeaninteger constant and the data type can be any valid C++ data type.
  • 30. ARRAYINITIALIZATION  In C++elements of an array can be initialized one by one or using asingle statement float balance[5]={1000.0, 2.0, 3.4,7.0, 50};  The number of values between braces { } cannot be larger than the number of elements that we declare for the array between square brackets [ ].
  • 31. C++ARRAYINDETAIL CONCEPT DESCRIPTION Multi-dimensional arrays C++supportsmultidimensionalarrays.Thesimplest form of the multidimensional array is the two- dimensional array. Pointer to an array Youcangenerateapointertothefirstelementofan arraybysimplyspecifyingthearrayname,withoutany index. Passing arrays to functions You can pass to the function a pointer to an array by specifying the array's name without an index. Return array from functions C++ allows a function to return an array.
  • 32. POINTERS  Pointer is a user defined data type which creates special types of variables which can hold the address of primitive data type like char, int, float, double or user defined data type like function, pointer etc. or derived data type like array, structure, union, enum. WhatAre Pointers?  A pointer is a variable whose value is the address of another variable. Like any variable or constant, you must declare a pointer before you can work with it. Syntax datatype *var-name;
  • 33. int *ip; double*dp; float *fp; char *ch // pointer toaninteger // pointer toadouble // pointer toafloat // pointer tocharacter
  • 34. USINGPOINTERSINC++  Therearefewimportantoperations,whichwewill dowith the pointers very frequently. (a) wedefinea pointer variables (b) assign the address of a variable to a pointer and (c) finally access the value at the address available in the pointer variable.  This is done by using unary operator * that returns the value of the variable located at the address specified by its operand.
  • 35. C++ POINTERSINDETAIL CONCEPT DESCRIPTION C++ Null Pointers C++supportsnullpointer,whichisaconstantwitha value of zero defined in several standard libraries. C++ pointer arithmetic There are four arithmetic operators that can be used on pointers: ++, --, +, - C++ pointers vs. arrays Thereis acloserelationship between pointers andarrays. Let us check how? C++ array of pointers You can define arrays to hold a number of pointers. C++ pointer to pointer C++ allows you to have pointer on a pointer and so on. Passing pointers to functions Passing an argument by reference or by address both enable the passed argument to be changed in the calling function by the called function. Return pointer from functions C++ allows a function to return a pointer to local
  • 36. C++ STRINGS  The following declaration and initialization create a string consisting of the word "Hello". To hold the null character at the end of the array, the size of the character array containing the string is one more than the number of characters in the word "Hello.“  Method1: char greeting[6] ={'H', 'e', 'l', 'l', 'o', '0'};  Method2: char greeting[] ="Hello";
  • 37.
  • 38. #include <iostream.h> int main () { char greeting[6] ={'H', 'e', 'l', 'l', 'o', '0'}; cout <<"Greeting message: "; cout <<greeting << endl; return 0; } OUTPU T OUTPUT Greetingmessage: Hello
  • 39. Functions Purpose strcpy(s1, s2); Copies string s2 into string s1. strcat(s1, s2); Concatenatesstrings2ontotheendofstring s1. strlen(s1); Returns the length of string s1. strcmp(s1, s2); Returns0if s1ands2arethesame;lessthan0if s1<s2; greater than 0 if s1>s2. strchr(s1, ch); Returnsapointertothefirstoccurrenceofcharacterchinstring s1. strstr(s1, s2); Returnsapointertothefirstoccurrenceofstrings2in string s1.
  • 40. #include<iostream> #include<cstring> int main() { char str1[10] ="Hello"; char str2[10] ="World"; char str3[10]; int len; strcpy( str3, str1); // copystr1intostr3 cout <<"strcpy( str3, str1) : " <<str3<< endl; strcat( str1, str2); // concatenatesstr1 andstr2 cout <<"strcat( str1, str2): " <<str1<< endl; len =strlen(str1); // total length of str1 after concatenation cout <<"strlen(str1) : " <<len << endl; return0; }
  • 41. FILEHANDLINGINC++  File Handling concept in C++ language is used for store a data permanently in computer. Using file handling we can store our data in Secondary memory (Hard disk). Whyuse FileHandling For permanent storage. The transfer of input - data or output - data fromone computer to another can be easily done by using files.
  • 42.  Forreadandwritefromafile youneedanotherstandardC++ library called fstream, which defines three new data types: Datatype Description ofstream This is used to create a file and write data on files ifstream This is used to read data from files fstream This is used to both read and write data from/to files
  • 43. HOWTOACHIEVEFILEHANDLING For achieving file handling in C++we need follow following steps  Naming a file  Opening a file  Reading data fromfile  Writing data into file  Closing a file
  • 44. FUNCTIONSUSEINFILEHANDLING Function Operation open() To create a file close() To close an existing file get() Read a single character from a file put() write a single character in file. read() Read data from file write() Write data into file.
  • 45. FILEREADOPERATION #include<conio.h> #include<fstream.h> int main() { char c,fname[10]; cout<<"Enter file name:"; cin>>fname; ifstreamin(fname); if(!in) { cout<<"FileDoes not Exist"; getch(); return0; } cout<<"nn"; while(in.eof()==0) { in.get(c); cout<<c; } getch(); }
  • 46. FILEWRITEOPERATION #include<iostream.h> #include<stdio.h> #include<conio.h> #include<fstream.h> int main() { char c,fname[10]; ofstreamout; cout<<"Enter File name:"; cin>>fname; out.open(fname); cout<<"Enter contents to store in file (Enter # at end):n"; while((c=getchar())!='#') } { out<<c; out.close(); getch(); return 0; }