SlideShare a Scribd company logo
BASICS OF C++
BY
ANANTHU G
College of Engineering Perumon
Introduction
Why using C++ ?
ANSI Standard.
Compilers available on all platforms.
All libraries consits of c or c++ API .
Is C++ better than Fortran ?
Struture
Object orientation
Error checking during compiling
2
╺ In 1979, Bjarne Stroustrup, a Danish computer scientist, began work on "C with
Classes", the predecessor to C++.
╺ Started in 1978 and released the first version in 1979 at AT and T Bell Labs.
╺ In 1983 it was named as C++.
╺ The C++ is also the 4th most used language.
3
HISTORY OF C++
C++ Program Fomat
#include <iostream.h> // preprocessor directive or header files
#include<conio.h> // preprocessor directive
void main() { // statement block enclosed by { and }
clrscr(); // clears the output screen
cout << "Hello World"; // prints Hello World
getch(); // get a character to terminate from output screen
endl:} //either endl or return 0 can be used to end the program
All c++ programs have only one main function.
It can either return as void main() or int main()
4
C Language
•Designed by Dennis Ritchie
•Appeared in1972
•Language TypeProcedural
Oriented Language
•Execution Flow Top to Bottom
Comparison C and C++
C++ Language
•Designed by Bjarne Stroustrup
• Appeared in1985
•Language Type Multi-Paradigm
Object Oriented Language
•Execution Flow Top to Bottom
5
Data Types in C++
Data Type
╺ Boolean
╺ Character
╺ Integer
╺ Floating point
╺ Double floating point
╺ Valueless
Keyword
╺ bool ( 1 bit)
╺ char ( 1 bit)
╺ int (4 bit)
╺ float ( 4 bit)
╺ double ( 8 bit)
╺ void
6
Functions
╺ In programming, function refers to a segment that groups code to perform a
specific task.
╺ Depending on whether a function is predefined or created by programmer;
there are two types of function:
 Library Function
 User-defined Function
7
Library Function
Library functions are the built-in function in C++ programming.
Programmer can use library function by invoking function directly;
they don't need to write it themselves.
8
User-defined Function
C++ allows programmer to define their own function.
A user-defined function groups code to perform a specific task and that group
of code is given a name(identifier).
When the function is invoked from any part of program, it all executes the
codes defined in the body of function.
9
Function prototype (declaration)
If a user-defined function is defined after main() function, compiler will show error.
It is because compiler is unaware of user-defined function, types of argument
passed to function and return type.
In C++, function prototype is a declaration of function without its body to give
compiler information about user-defined function. Function prototype in the
above example is:
int add(int, int);
You can see that, there is no body of function in prototype. Also, there are only
return type of arguments but no arguments. You can also declare function
prototype as below but it's not necessary to write arguments.
int add(int a, int b);
Note: It is not necessary to define prototype if user-defined function exists
before main() function.
10
Function Definition
The function itself is referred as function definition. Function definition in the
above program is:
// Function definition
int add(int a,int b)
{ int add;
add = a + b;
return add; }
When the function is called, control is transferred to the first statement of the
function body.
Then, other statements in function body are executed sequentially.
When all codes inside function definition is executed, control of program moves
to the calling program.
11
Function Call
To execute the codes of function body, the user-defined function needs to be
invoked(called).
In the above program, add(num1,num2); inside main() function calls the user-
defined function.
The function returns an integer which is stored in variable add.
12
Local Variables
Variables that are declared inside a function or block are local variables. They
can be used only by statements that are inside that function or block of
code. Local variables are not known to functions outside their own.
Global Variables
Global variables are defined outside of all the functions, usually on top of the
program. The global variables will hold their value throughout the life-time of
your program.
A global variable can be accessed by any function. That is, a global variable is
available for use throughout your entire program after its declaration.
13
Thanks!
Any questions?
You can find me at
ananthuachu444@gmail.com
14

More Related Content

PPT
Csc1100 lecture06 ch06_pt2
PDF
A tutorial on C++ Programming
PPTX
C structure
PPT
Csc1100 lecture05 ch05
PDF
Unit 3 (1)
PDF
C programming session8
PPTX
My first program in c, hello world !
Csc1100 lecture06 ch06_pt2
A tutorial on C++ Programming
C structure
Csc1100 lecture05 ch05
Unit 3 (1)
C programming session8
My first program in c, hello world !

What's hot (20)

PDF
C language
PPTX
Evaluation of postfix expression
PPTX
Basic c programming and explanation PPT1
PPTX
Functions in C
PPTX
Functions in c
PPTX
C Program Structure
PPTX
Infix to postfix
PDF
computer notes - Conversion from infix to postfix
PDF
C programming session7
PPT
Lecture 2
DOCX
Programming Global variable
PPT
Infix to Postfix Conversion Using Stack
PPTX
Infix-Postfix expression conversion
PDF
Session 5-exersice
PPT
Structure of a C program
PPTX
Function in c programming
PPTX
Infix to postfix conversion
PPTX
Infix postfixcoversion
PPTX
User defined functions.1
PDF
Chapter 11 Function
C language
Evaluation of postfix expression
Basic c programming and explanation PPT1
Functions in C
Functions in c
C Program Structure
Infix to postfix
computer notes - Conversion from infix to postfix
C programming session7
Lecture 2
Programming Global variable
Infix to Postfix Conversion Using Stack
Infix-Postfix expression conversion
Session 5-exersice
Structure of a C program
Function in c programming
Infix to postfix conversion
Infix postfixcoversion
User defined functions.1
Chapter 11 Function
Ad

Similar to Cpp (20)

PPTX
C++ Constructs.pptx
PPTX
cbybalaguruswami-e-180803051831.pptx
PPTX
cbybalaguruswami-e-180803051831.pptx
DOC
C notes diploma-ee-3rd-sem
PPTX
Introduction to cpp language and all the required information relating to it
PDF
Cp week _2.
PPTX
Presentation on Function in C Programming
PPTX
Unit-III.pptx
PPTX
Functions and Header files ver very useful
PPT
POLITEKNIK MALAYSIA
DOC
Basic construction of c
PPTX
Embedded C.pptx
PDF
Introduction of c language
PPTX
computer programming omputer programming
PDF
C Programming Tutorial - www.infomtec.com
PDF
PPTX
structured Programming Unit-7-Functions.pptx
PDF
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
PPTX
Presentation on C language By Kirtika thakur
C++ Constructs.pptx
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
C notes diploma-ee-3rd-sem
Introduction to cpp language and all the required information relating to it
Cp week _2.
Presentation on Function in C Programming
Unit-III.pptx
Functions and Header files ver very useful
POLITEKNIK MALAYSIA
Basic construction of c
Embedded C.pptx
Introduction of c language
computer programming omputer programming
C Programming Tutorial - www.infomtec.com
structured Programming Unit-7-Functions.pptx
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Presentation on C language By Kirtika thakur
Ad

Recently uploaded (20)

PDF
Computing-Curriculum for Schools in Ghana
PDF
RMMM.pdf make it easy to upload and study
PDF
Insiders guide to clinical Medicine.pdf
PDF
Classroom Observation Tools for Teachers
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
01-Introduction-to-Information-Management.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Cell Types and Its function , kingdom of life
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Computing-Curriculum for Schools in Ghana
RMMM.pdf make it easy to upload and study
Insiders guide to clinical Medicine.pdf
Classroom Observation Tools for Teachers
102 student loan defaulters named and shamed – Is someone you know on the list?
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPH.pptx obstetrics and gynecology in nursing
Microbial disease of the cardiovascular and lymphatic systems
01-Introduction-to-Information-Management.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Pharma ospi slides which help in ospi learning
TR - Agricultural Crops Production NC III.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
VCE English Exam - Section C Student Revision Booklet
Cell Types and Its function , kingdom of life
Microbial diseases, their pathogenesis and prophylaxis
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student

Cpp

  • 1. BASICS OF C++ BY ANANTHU G College of Engineering Perumon
  • 2. Introduction Why using C++ ? ANSI Standard. Compilers available on all platforms. All libraries consits of c or c++ API . Is C++ better than Fortran ? Struture Object orientation Error checking during compiling 2
  • 3. ╺ In 1979, Bjarne Stroustrup, a Danish computer scientist, began work on "C with Classes", the predecessor to C++. ╺ Started in 1978 and released the first version in 1979 at AT and T Bell Labs. ╺ In 1983 it was named as C++. ╺ The C++ is also the 4th most used language. 3 HISTORY OF C++
  • 4. C++ Program Fomat #include <iostream.h> // preprocessor directive or header files #include<conio.h> // preprocessor directive void main() { // statement block enclosed by { and } clrscr(); // clears the output screen cout << "Hello World"; // prints Hello World getch(); // get a character to terminate from output screen endl:} //either endl or return 0 can be used to end the program All c++ programs have only one main function. It can either return as void main() or int main() 4
  • 5. C Language •Designed by Dennis Ritchie •Appeared in1972 •Language TypeProcedural Oriented Language •Execution Flow Top to Bottom Comparison C and C++ C++ Language •Designed by Bjarne Stroustrup • Appeared in1985 •Language Type Multi-Paradigm Object Oriented Language •Execution Flow Top to Bottom 5
  • 6. Data Types in C++ Data Type ╺ Boolean ╺ Character ╺ Integer ╺ Floating point ╺ Double floating point ╺ Valueless Keyword ╺ bool ( 1 bit) ╺ char ( 1 bit) ╺ int (4 bit) ╺ float ( 4 bit) ╺ double ( 8 bit) ╺ void 6
  • 7. Functions ╺ In programming, function refers to a segment that groups code to perform a specific task. ╺ Depending on whether a function is predefined or created by programmer; there are two types of function:  Library Function  User-defined Function 7
  • 8. Library Function Library functions are the built-in function in C++ programming. Programmer can use library function by invoking function directly; they don't need to write it themselves. 8
  • 9. User-defined Function C++ allows programmer to define their own function. A user-defined function groups code to perform a specific task and that group of code is given a name(identifier). When the function is invoked from any part of program, it all executes the codes defined in the body of function. 9
  • 10. Function prototype (declaration) If a user-defined function is defined after main() function, compiler will show error. It is because compiler is unaware of user-defined function, types of argument passed to function and return type. In C++, function prototype is a declaration of function without its body to give compiler information about user-defined function. Function prototype in the above example is: int add(int, int); You can see that, there is no body of function in prototype. Also, there are only return type of arguments but no arguments. You can also declare function prototype as below but it's not necessary to write arguments. int add(int a, int b); Note: It is not necessary to define prototype if user-defined function exists before main() function. 10
  • 11. Function Definition The function itself is referred as function definition. Function definition in the above program is: // Function definition int add(int a,int b) { int add; add = a + b; return add; } When the function is called, control is transferred to the first statement of the function body. Then, other statements in function body are executed sequentially. When all codes inside function definition is executed, control of program moves to the calling program. 11
  • 12. Function Call To execute the codes of function body, the user-defined function needs to be invoked(called). In the above program, add(num1,num2); inside main() function calls the user- defined function. The function returns an integer which is stored in variable add. 12
  • 13. Local Variables Variables that are declared inside a function or block are local variables. They can be used only by statements that are inside that function or block of code. Local variables are not known to functions outside their own. Global Variables Global variables are defined outside of all the functions, usually on top of the program. The global variables will hold their value throughout the life-time of your program. A global variable can be accessed by any function. That is, a global variable is available for use throughout your entire program after its declaration. 13
  • 14. Thanks! Any questions? You can find me at ananthuachu444@gmail.com 14