SlideShare a Scribd company logo
1 of 19
Submitted By:- Albert Sihota
Submitted to:- Prof Jagdeep Singh   Branch:- CSE N1
                                    Roll No.:- 115302
   Readings: 1.1-1.3, 1.9-1.13, 1.16-1.18, 1.21-1.22
   C++
       Bjarne Stroustrup (Bell Labs, 1979)
       started as extension to C (macros and variables)
       added new useful, features
       nowadays a language of its own
       C++ (the next thing after C, though wouldn’t ++C be
        more appropriate?)
Intro to C++
  Object-Oriented Programming
  Changes in C++
    comments
    variable declaration location
    initialization
    pointer changes
    tagged structure type
    enum types
    bool type
   First-class objects - atomic types in C
       int, float, char
       have:
         values
         sets of operations that can be applied to them
       how represented irrelevant to how they are
        manipulated
   Other objects - structures in C
       cannot be printed
       do not have operations associated with them (at
        least, not directly)
   Make all objects, whether C-defined or user-
    defined, first-class objects
   For C++ structures (called classes) allow:
       functions to be associated with the class
       only allow certain functions to access the internals of
        the class
       allow the user to re-define existing functions (for
        example, input and output) to work on class
   Classes
       similar to structures in C (in fact, you can can still
        use the struct definition)
       have fields corresponding to fields of a structure in C
        (similar to variables)
       have fields corresponding to functions in C
        (functions that can be applied to that structure)
       some fields are accessible by everyone, some not
        (data hiding)
       some fields shared by the entire class
   A class in C++ is like a type in C
   Variables created of a particular class are
    instances of that class
   Variables have values for fields of the class
   Class example: Student
       has name, id, gpa, etc. fields that store values
       has functions, changeGPA, addCredits, that can be
        applied to instances of that class
   Instance examples: John Doe, Jane Doe
       each with their own values for the fields of the class
   Can use C form of comments /* A Comment
    */
   Can also use // form:
       when // encountered, remainder of line ignored
       works only on that line
   Examples:
    void main() {
      int I; // Variable used in loops
      char C; // No comment comment
   In C++, variable declarations are not restricted
    to the beginnings of blocks (before any code)
       you may interleave declarations/statements as
        needed
       it is still good style to have declarations first
   Example
    void main() {
      int I = 5;
      printf(“Please enter J: “);
      int J; // Not declared at the start
      scanf(“%d”,&J);
   You can declare the variable(s) used in a for
    loop in the initialization section of the for loop
       good when counter used in for loop only exists in for
        loop (variable is throw-away)
   Example
    for (int I = 0; I < 5; I++)
      printf(“%dn”,I);
   Variable exists only during for loop (goes away
    when loop ends)
   Not restricted to using constant literal values in
    initializing global variables, can use any
    evaluable expression
   Example:
    int rows = 5;
    int cols = 6;
    int size = rows * cols;

    void main() {
    ...
   When giving a list of initial array values in C+
    +, you can use expressions that have to be
    evaluated
   Values calculated at run-time before
    initialization done
   Example:
    void main() {
      int n1, n2, n3;
      int *nptr[] = { &n1, &n2, &n3 };
   In C it is legal to cast other pointers to and from
    a void *
   In C++ this is an error, to cast you should use
    an explicit casting command
   Example:
    int N;
    int *P = &N;
    void *Q = P;          // illegal in C++
    void *R = (void *) P; // ok
   C++ does not use the value NULL, instead
    NULL is always 0 in C++, so we simply use 0
   Example:
    int *P = 0; // equivalent to
                // setting P to NULL
   Can check for a 0 pointer as if true/false:
    if (!P) // P is 0 (NULL)
      ...
    else // P is not 0 (non-NULL)
      ...
   When using struct command in C++ (and for
    other tagged types), can create type using tag
    format and not use tag in variable declaration:
    struct MyType {
       int A;
       float B;
    };
    MyType V;
   Enumerated types not directly represented as
    integers in C++
       certain operations that are legal in C do not work in
        C++
   Example:
    void main() {
      enum Color { red, blue, green };
      Color c = red;
      c = blue;
      c = 1; // Error in C++
      ++c; // Error in C++
   C has no explicit type for true/false values
   C++ introduces type bool (later versions of C+
    +)
       also adds two new bool literal constants true (1) and
        false (0)
   Other integral types (int, char, etc.) are
    implicitly converted to bool when appropriate
       non-zero values are converted to true
       zero values are converted to false
   Operators requiring bool value(s) and
    producing a bool value:
    && (And), || (Or), ! (Not)
   Relational operators (==, !=, <, >, <=, >=)
    produce bool values
   Some statements expect expressions that
    produce bool values:
     if (boolean_expression)
      while (boolean_expression)
      do … while (boolean_expression)
      for ( ; boolean_expression; )
C++ Introduction

More Related Content

What's hot

Csc1100 lecture06 ch06_pt2
Csc1100 lecture06 ch06_pt2Csc1100 lecture06 ch06_pt2
Csc1100 lecture06 ch06_pt2IIUM
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04IIUM
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xiiSyed Zaid Irshad
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 FeaturesJan Rüegg
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteachingeteaching
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CSyed Mustafa
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageVincenzo De Florio
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c languageRai University
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdSyed Mustafa
 

What's hot (20)

Csc1100 lecture06 ch06_pt2
Csc1100 lecture06 ch06_pt2Csc1100 lecture06 ch06_pt2
Csc1100 lecture06 ch06_pt2
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
CP Handout#8
CP Handout#8CP Handout#8
CP Handout#8
 
Assignment10
Assignment10Assignment10
Assignment10
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
 
Assignment8
Assignment8Assignment8
Assignment8
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
Chaptr 1
Chaptr 1Chaptr 1
Chaptr 1
 
C language basics
C language basicsC language basics
C language basics
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
Oops
OopsOops
Oops
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
Assignment6
Assignment6Assignment6
Assignment6
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
 

Viewers also liked

Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networkingparmsidhu
 
open source technology
open source technologyopen source technology
open source technologyparmsidhu
 
Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networkingparmsidhu
 
Biometric Sensors
Biometric SensorsBiometric Sensors
Biometric Sensorsparmsidhu
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 

Viewers also liked (8)

Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networking
 
open source technology
open source technologyopen source technology
open source technology
 
Parm
ParmParm
Parm
 
Parm
ParmParm
Parm
 
Mobile Networking
Mobile NetworkingMobile Networking
Mobile Networking
 
Biometric Sensors
Biometric SensorsBiometric Sensors
Biometric Sensors
 
(2012) Evolution of the Human Biometric Sensor Interaction model
(2012) Evolution of the Human Biometric Sensor Interaction model(2012) Evolution of the Human Biometric Sensor Interaction model
(2012) Evolution of the Human Biometric Sensor Interaction model
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 

Similar to C++ Introduction

Similar to C++ Introduction (20)

C++Chapter01.PPT
C++Chapter01.PPTC++Chapter01.PPT
C++Chapter01.PPT
 
Introduction to C++ programming language
Introduction to C++ programming languageIntroduction to C++ programming language
Introduction to C++ programming language
 
C++Chapter01(2).PPT
C++Chapter01(2).PPTC++Chapter01(2).PPT
C++Chapter01(2).PPT
 
2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++
 
C –FAQ:
C –FAQ:C –FAQ:
C –FAQ:
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
 
C programming notes
C programming notesC programming notes
C programming notes
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
 
Apa style-1 (1)
Apa style-1 (1)Apa style-1 (1)
Apa style-1 (1)
 
Interview Questions For C Language
Interview Questions For C Language Interview Questions For C Language
Interview Questions For C Language
 

Recently uploaded

AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 

Recently uploaded (20)

AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 

C++ Introduction

  • 1. Submitted By:- Albert Sihota Submitted to:- Prof Jagdeep Singh Branch:- CSE N1 Roll No.:- 115302
  • 2. Readings: 1.1-1.3, 1.9-1.13, 1.16-1.18, 1.21-1.22  C++  Bjarne Stroustrup (Bell Labs, 1979)  started as extension to C (macros and variables)  added new useful, features  nowadays a language of its own  C++ (the next thing after C, though wouldn’t ++C be more appropriate?)
  • 3. Intro to C++ Object-Oriented Programming Changes in C++ comments variable declaration location initialization pointer changes tagged structure type enum types bool type
  • 4. First-class objects - atomic types in C  int, float, char  have:  values  sets of operations that can be applied to them  how represented irrelevant to how they are manipulated  Other objects - structures in C  cannot be printed  do not have operations associated with them (at least, not directly)
  • 5. Make all objects, whether C-defined or user- defined, first-class objects  For C++ structures (called classes) allow:  functions to be associated with the class  only allow certain functions to access the internals of the class  allow the user to re-define existing functions (for example, input and output) to work on class
  • 6. Classes  similar to structures in C (in fact, you can can still use the struct definition)  have fields corresponding to fields of a structure in C (similar to variables)  have fields corresponding to functions in C (functions that can be applied to that structure)  some fields are accessible by everyone, some not (data hiding)  some fields shared by the entire class
  • 7. A class in C++ is like a type in C  Variables created of a particular class are instances of that class  Variables have values for fields of the class  Class example: Student  has name, id, gpa, etc. fields that store values  has functions, changeGPA, addCredits, that can be applied to instances of that class  Instance examples: John Doe, Jane Doe  each with their own values for the fields of the class
  • 8. Can use C form of comments /* A Comment */  Can also use // form:  when // encountered, remainder of line ignored  works only on that line  Examples: void main() { int I; // Variable used in loops char C; // No comment comment
  • 9. In C++, variable declarations are not restricted to the beginnings of blocks (before any code)  you may interleave declarations/statements as needed  it is still good style to have declarations first  Example void main() { int I = 5; printf(“Please enter J: “); int J; // Not declared at the start scanf(“%d”,&J);
  • 10. You can declare the variable(s) used in a for loop in the initialization section of the for loop  good when counter used in for loop only exists in for loop (variable is throw-away)  Example for (int I = 0; I < 5; I++) printf(“%dn”,I);  Variable exists only during for loop (goes away when loop ends)
  • 11. Not restricted to using constant literal values in initializing global variables, can use any evaluable expression  Example: int rows = 5; int cols = 6; int size = rows * cols; void main() { ...
  • 12. When giving a list of initial array values in C+ +, you can use expressions that have to be evaluated  Values calculated at run-time before initialization done  Example: void main() { int n1, n2, n3; int *nptr[] = { &n1, &n2, &n3 };
  • 13. In C it is legal to cast other pointers to and from a void *  In C++ this is an error, to cast you should use an explicit casting command  Example: int N; int *P = &N; void *Q = P; // illegal in C++ void *R = (void *) P; // ok
  • 14. C++ does not use the value NULL, instead NULL is always 0 in C++, so we simply use 0  Example: int *P = 0; // equivalent to // setting P to NULL  Can check for a 0 pointer as if true/false: if (!P) // P is 0 (NULL) ... else // P is not 0 (non-NULL) ...
  • 15. When using struct command in C++ (and for other tagged types), can create type using tag format and not use tag in variable declaration: struct MyType { int A; float B; }; MyType V;
  • 16. Enumerated types not directly represented as integers in C++  certain operations that are legal in C do not work in C++  Example: void main() { enum Color { red, blue, green }; Color c = red; c = blue; c = 1; // Error in C++ ++c; // Error in C++
  • 17. C has no explicit type for true/false values  C++ introduces type bool (later versions of C+ +)  also adds two new bool literal constants true (1) and false (0)  Other integral types (int, char, etc.) are implicitly converted to bool when appropriate  non-zero values are converted to true  zero values are converted to false
  • 18. Operators requiring bool value(s) and producing a bool value: && (And), || (Or), ! (Not)  Relational operators (==, !=, <, >, <=, >=) produce bool values  Some statements expect expressions that produce bool values: if (boolean_expression) while (boolean_expression) do … while (boolean_expression) for ( ; boolean_expression; )