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_pt2
IIUM
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04
IIUM
 

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 (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

Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
Rokonuzzaman Rony
 

Similar to C++ Introduction (20)

C++Chapter01(2).PPT
C++Chapter01(2).PPTC++Chapter01(2).PPT
C++Chapter01(2).PPT
 
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
 
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

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

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; )