SlideShare a Scribd company logo
1 of 19
Programming Fundamentals 
Lecture No 2
History 
• In 1967 BCPL language was created by Master Martin used to write operating 
systems and compilers. 
• 2 years later B language was developed by Ken Thomas. UNIX operating system 
was developed in B in 1970. It is a type less language. Each data item occupy one 
word in memory. 
• In 1972 C language was developed by Dennis Ritche. It is the combination of B 
and BCPL. New features like data types were also added. UNIX was revised in C. 
C language is computer independent language. A program written in C can run on 
any computer 
• In 1980’s C++ was developed by Bjarne Stroustrup which is the extension of C. 
C++ was designed for UNIX system environment. C++ enabled programmers to 
improve the quality of code. It includes object oriented programming.
C++ Compiler 
• C++ compiler translates a C++ source program to machine code. 
Machine code is also known as object code. 
• It is stored in new files with the extension obj. The object code is then 
linked to the libraries. After linking object code to the libraries an 
executable file extension exe is created. 
• The executable program is then run from operating system command 
line. 
a.cpp 
a.obj 
a.exe
Structure of C++ 
1 Preprocessor Directives 
2 main ( ) function 
3 C++ statements
Preprocessor/ Compiler Directives 
• The instructions given to the compiler before the beginning of the actual program 
are called preprocessor or compiler directives. 
• The preprocessor consists of instructions for the compiler. 
• Preprocessor directives normally start with a number sign ( # )and the keyword 
“include”. 
• Preprocessor directives are used to include header files in the program. 
# include <iostream.h> 
main() 
{ 
Cout << “ This is my first program”; 
}
Header File 
• Header file is a C++ source file that contains definitions of library 
functions/objects. Header files are added into the program at the 
compilation of the program. A header file is added is added if the 
function defined in it is to be used in the program. 
• C++ has a large number of header files in which library functions are 
defined. 
• The header file must be included in the program before calling its 
function in the program. A single header file may contain a large 
number of built in library functions 
# include < name of the header file >
main( ) Function 
• The main( ) function indicates the beginning of C++ program. main( ) must 
be included in every C++ program. 
• When a C++ program is executed, the control goes directly to the main( ) 
function. 
• The statements within this function are the main body of the C++ program. 
• If main function is not included, the program is not compiled and an error 
message is generated. 
main ( ) 
{ 
Program statements 
}
C++ Statements 
• The statements of the program are written under the main( ) 
function between curly braces { }. These statements are the 
body of the program. 
• Each statement in C++ ends with a semicolon (;) 
• C++ is a case sensitive language. The C++ statements are 
normally written in lower case letters but in some cases these 
can also be written in uppercase.
Keywords 
• The words used by the language for special purposes are 
called keywords. 
• These are also called reserved words. 
• In C++ program, the word main is used to indicate the 
starting of the program, include is used to add header files, 
int to declare an integer type variable. 
• The keywords cannot be used as variable names in a 
program.
Tokens 
• A program statement consists of variable names, keywords, constants, 
punctuation marks, operators etc. In C++, these elements of a 
statement are called tokens. 
• In the following program segment: 
main() 
{ 
Int a,b; 
} 
• main,{,},int,a,b, punctuation marks (,) and (;) are tokens of the 
program
Variables 
• A quantity whose value may change during the execution of the 
program is called variable. It is represented by symbol or name. 
• A variable represents a storage or memory location in the 
computer memory. Data is stored into the memory location. 
• The name of the memory location and variable name remains 
fixed during execution of the program. 
• But data stored in the location may change from time to time. 
• A variable is also known as object in C++. 
• In C++ a variable name consists of alphabets and digits.
Rules of Writing variables 
• The first character of a variable name must be an 
alphabet character. 
• Blank spaces are not allowed in the variable name. 
• Special characters such as arithmetic operators #, ^ 
cannot be used in the variable name. 
• A variable name declared for one data type cannot be 
used to declare another data type.
Data Types in C++ 
1 Int Integer 
2 float Floating Point 
3 double Double Precision 
4 char Characters 
5 bool Boolean
Declaration of Variables 
• Assigning the name and data type that a variable can hold is called the declaration 
of the variable. 
• All variables that are used in a program are declared using variable declaration 
statement. 
• Syntax : 
• Type list of variables; 
Type = int, float etc 
Variables = abc, xyz, s,e etc 
Int abc, xyz, d, s; 
float b; 
char num [15];
Initialization of Variables 
• When a variable is declared, a memory location is assigned to it. 
• The value is assigned at the time of declaration. 
• Assigning known value to a variable at the time of its declaration 
is called initializing of the variable. 
Int a = 110, b = 60, c;
Arithmetic Operators 
• The arithmetic operators are the symbols that represent 
arithmetic operations. These are used in arithmetic expressions. 
Each arithmetic operator operates upon two numeric values and 
returns a value. 
Operator Meaning 
+ Addition 
- Subtraction 
* Multiplication 
/ Division 
% For remainder
Arithmetic Expression 
• An arithmetic expression is a combination of variables, constants 
and arithmetic operators. 
• It is used to calculate the value of an arithmetic formula. 
• The value of the expression is assigned to a variable on the left side 
of “=“ operator. This variable is also known as the receiving 
variable. 
• The operator ”=“ is called the assignment operator. It is used to 
assign the calculated value of the expression to the receiving 
variable.
Arithmetic Expression 
Examples: 
m= 10, x =5; 
m * x + 100 
res = m * x + 100; 
a = 10; 
c + d = 250;
Programming Fundamental Slide lecture no.2 (Section E)

More Related Content

What's hot

7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab MashaelQ
 
Spr ch-05-compilers
Spr ch-05-compilersSpr ch-05-compilers
Spr ch-05-compilersVasim Pathan
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionSarmad Ali
 
Workshop Assembler
Workshop AssemblerWorkshop Assembler
Workshop AssemblerTuhin_Das
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Bhavin Darji
 
Toy compiler
Toy compilerToy compiler
Toy compilerhome
 
Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design FileArchita Misra
 
Code generation errors and recovery
Code generation errors and recoveryCode generation errors and recovery
Code generation errors and recoveryMomina Idrees
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolMashaelQ
 
Object oriented programming 11 preprocessor directives and program structure
Object oriented programming 11 preprocessor directives and program structureObject oriented programming 11 preprocessor directives and program structure
Object oriented programming 11 preprocessor directives and program structureVaibhav Khanna
 
phases of compiler-analysis phase
phases of compiler-analysis phasephases of compiler-analysis phase
phases of compiler-analysis phaseSuyash Srivastava
 

What's hot (20)

phases of a compiler
 phases of a compiler phases of a compiler
phases of a compiler
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab
 
Spr ch-05-compilers
Spr ch-05-compilersSpr ch-05-compilers
Spr ch-05-compilers
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Workshop Assembler
Workshop AssemblerWorkshop Assembler
Workshop Assembler
 
Yacc
YaccYacc
Yacc
 
Phases of a Compiler
Phases of a CompilerPhases of a Compiler
Phases of a Compiler
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
 
Toy compiler
Toy compilerToy compiler
Toy compiler
 
Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design File
 
Analysis of the source program
Analysis of the source programAnalysis of the source program
Analysis of the source program
 
Code generation errors and recovery
Code generation errors and recoveryCode generation errors and recovery
Code generation errors and recovery
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
 
Object oriented programming 11 preprocessor directives and program structure
Object oriented programming 11 preprocessor directives and program structureObject oriented programming 11 preprocessor directives and program structure
Object oriented programming 11 preprocessor directives and program structure
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
phases of compiler-analysis phase
phases of compiler-analysis phasephases of compiler-analysis phase
phases of compiler-analysis phase
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Lexical Analyzers and Parsers
Lexical Analyzers and ParsersLexical Analyzers and Parsers
Lexical Analyzers and Parsers
 

Viewers also liked

Programming fundamental
Programming fundamentalProgramming fundamental
Programming fundamentalMukesh Thakur
 
Fundamentals of programming final
Fundamentals of programming finalFundamentals of programming final
Fundamentals of programming finalRicky Recto
 
Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Arslan Hussain
 
Fundamental Programming Lect 1
Fundamental Programming Lect 1Fundamental Programming Lect 1
Fundamental Programming Lect 1Namrah Erum
 
Introduction to Programming Languages
Introduction to Programming LanguagesIntroduction to Programming Languages
Introduction to Programming Languageseducationfront
 
Programming languages
Programming languagesProgramming languages
Programming languagesAkash Varaiya
 
Programming languages
Programming languagesProgramming languages
Programming languagesAsmasum
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languagesVarun Garg
 

Viewers also liked (11)

Programming fundamental
Programming fundamentalProgramming fundamental
Programming fundamental
 
Comp 107 cep ii
Comp 107 cep iiComp 107 cep ii
Comp 107 cep ii
 
Fundamentals of programming final
Fundamentals of programming finalFundamentals of programming final
Fundamentals of programming final
 
Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Programming Fundamental Slide No.1
Programming Fundamental Slide No.1
 
Fundamental Programming Lect 1
Fundamental Programming Lect 1Fundamental Programming Lect 1
Fundamental Programming Lect 1
 
Introduction to Programming Languages
Introduction to Programming LanguagesIntroduction to Programming Languages
Introduction to Programming Languages
 
Computer languages
Computer languagesComputer languages
Computer languages
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Computer Languages.
Computer Languages.Computer Languages.
Computer Languages.
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 

Similar to Programming Fundamental Slide lecture no.2 (Section E)

Similar to Programming Fundamental Slide lecture no.2 (Section E) (20)

Rr
RrRr
Rr
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
 
C pdf
C pdfC pdf
C pdf
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
CP c++ programing project Unit 1 intro.pdf
CP c++ programing project  Unit 1 intro.pdfCP c++ programing project  Unit 1 intro.pdf
CP c++ programing project Unit 1 intro.pdf
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 
C language ppt
C language pptC language ppt
C language ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
Pc module1
Pc module1Pc module1
Pc module1
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
#Code2 create c++ for beginners
#Code2 create  c++ for beginners #Code2 create  c++ for beginners
#Code2 create c++ for beginners
 

Recently uploaded

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
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)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
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
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 

Programming Fundamental Slide lecture no.2 (Section E)

  • 2. History • In 1967 BCPL language was created by Master Martin used to write operating systems and compilers. • 2 years later B language was developed by Ken Thomas. UNIX operating system was developed in B in 1970. It is a type less language. Each data item occupy one word in memory. • In 1972 C language was developed by Dennis Ritche. It is the combination of B and BCPL. New features like data types were also added. UNIX was revised in C. C language is computer independent language. A program written in C can run on any computer • In 1980’s C++ was developed by Bjarne Stroustrup which is the extension of C. C++ was designed for UNIX system environment. C++ enabled programmers to improve the quality of code. It includes object oriented programming.
  • 3. C++ Compiler • C++ compiler translates a C++ source program to machine code. Machine code is also known as object code. • It is stored in new files with the extension obj. The object code is then linked to the libraries. After linking object code to the libraries an executable file extension exe is created. • The executable program is then run from operating system command line. a.cpp a.obj a.exe
  • 4. Structure of C++ 1 Preprocessor Directives 2 main ( ) function 3 C++ statements
  • 5. Preprocessor/ Compiler Directives • The instructions given to the compiler before the beginning of the actual program are called preprocessor or compiler directives. • The preprocessor consists of instructions for the compiler. • Preprocessor directives normally start with a number sign ( # )and the keyword “include”. • Preprocessor directives are used to include header files in the program. # include <iostream.h> main() { Cout << “ This is my first program”; }
  • 6. Header File • Header file is a C++ source file that contains definitions of library functions/objects. Header files are added into the program at the compilation of the program. A header file is added is added if the function defined in it is to be used in the program. • C++ has a large number of header files in which library functions are defined. • The header file must be included in the program before calling its function in the program. A single header file may contain a large number of built in library functions # include < name of the header file >
  • 7. main( ) Function • The main( ) function indicates the beginning of C++ program. main( ) must be included in every C++ program. • When a C++ program is executed, the control goes directly to the main( ) function. • The statements within this function are the main body of the C++ program. • If main function is not included, the program is not compiled and an error message is generated. main ( ) { Program statements }
  • 8. C++ Statements • The statements of the program are written under the main( ) function between curly braces { }. These statements are the body of the program. • Each statement in C++ ends with a semicolon (;) • C++ is a case sensitive language. The C++ statements are normally written in lower case letters but in some cases these can also be written in uppercase.
  • 9. Keywords • The words used by the language for special purposes are called keywords. • These are also called reserved words. • In C++ program, the word main is used to indicate the starting of the program, include is used to add header files, int to declare an integer type variable. • The keywords cannot be used as variable names in a program.
  • 10. Tokens • A program statement consists of variable names, keywords, constants, punctuation marks, operators etc. In C++, these elements of a statement are called tokens. • In the following program segment: main() { Int a,b; } • main,{,},int,a,b, punctuation marks (,) and (;) are tokens of the program
  • 11. Variables • A quantity whose value may change during the execution of the program is called variable. It is represented by symbol or name. • A variable represents a storage or memory location in the computer memory. Data is stored into the memory location. • The name of the memory location and variable name remains fixed during execution of the program. • But data stored in the location may change from time to time. • A variable is also known as object in C++. • In C++ a variable name consists of alphabets and digits.
  • 12. Rules of Writing variables • The first character of a variable name must be an alphabet character. • Blank spaces are not allowed in the variable name. • Special characters such as arithmetic operators #, ^ cannot be used in the variable name. • A variable name declared for one data type cannot be used to declare another data type.
  • 13. Data Types in C++ 1 Int Integer 2 float Floating Point 3 double Double Precision 4 char Characters 5 bool Boolean
  • 14. Declaration of Variables • Assigning the name and data type that a variable can hold is called the declaration of the variable. • All variables that are used in a program are declared using variable declaration statement. • Syntax : • Type list of variables; Type = int, float etc Variables = abc, xyz, s,e etc Int abc, xyz, d, s; float b; char num [15];
  • 15. Initialization of Variables • When a variable is declared, a memory location is assigned to it. • The value is assigned at the time of declaration. • Assigning known value to a variable at the time of its declaration is called initializing of the variable. Int a = 110, b = 60, c;
  • 16. Arithmetic Operators • The arithmetic operators are the symbols that represent arithmetic operations. These are used in arithmetic expressions. Each arithmetic operator operates upon two numeric values and returns a value. Operator Meaning + Addition - Subtraction * Multiplication / Division % For remainder
  • 17. Arithmetic Expression • An arithmetic expression is a combination of variables, constants and arithmetic operators. • It is used to calculate the value of an arithmetic formula. • The value of the expression is assigned to a variable on the left side of “=“ operator. This variable is also known as the receiving variable. • The operator ”=“ is called the assignment operator. It is used to assign the calculated value of the expression to the receiving variable.
  • 18. Arithmetic Expression Examples: m= 10, x =5; m * x + 100 res = m * x + 100; a = 10; c + d = 250;