SlideShare a Scribd company logo
When to use a structure vs classes in c++
#1: When to Use a struct vs
Class
#6: How would you count
the occurrences of a string
within a string?
#11: Encrypt/Decrypt a
String in .NET
#16: How do I Make a Texbox
that Only Accepts Numbers?
#2: How Does One Parse
XML Files?
#7: How to Check if a
Number is a Power of 2
#12: How do I Get the
Index of the Current
Iteration of a foreach
Loop?
#17: How do I Round a Decimal
Value to 2 Places for Output?
#3: What is the Difference
between String and string
#8: C# Loop – break vs
continue
#13: How to Get My Own
IP address in C#
#18: Remove Duplicates from
an Array
#4: How do I get the
Application’s Path in a C#
Console App?
#9: Difference Between
abstract and virtual
functions
#14: How do I Calculate
Someone’s Age in C#?
#19: How do I Sort a Dictionary
by Value?
#5: Calling base Constructor
in C#
#10: Difference Between ref
and out Keywords
#15: How do I get the
String Value of an enum?
#20: How Can I Return Multiple
Values From a Function in C#?
• structs are value types that can contain data and functions
• structs are value types and do not require heap allocation.
• structs directly store their data in the struct, classes store a reference to a dynamically allocated object.
• structs are useful for small data structures
• structs can affect performance
• Constructors are invoked with the new operator, but that does not allocate memory on the heap
• A struct constructor simply returns the struct value itself (typically in a temporary location on the stack),
and this value is then copied as necessary
• With classes, multiple variables may have a reference to the same object
• It is possible for operations on one variable to affect the object referenced by the other variable.
• With structs, the variables each have their own copy of the data, and it is not possible for operations on
one to affect the other.
• structs do not support user-specified inheritance, and they implicitly inherit from type object

More Related Content

PPTX
Structure in c language
PPT
Structure in C
PDF
Structures in c++
PDF
Structures
PDF
Lecture18 structurein c.ppt
PPT
Structure c
PPTX
C programing -Structure
Structure in c language
Structure in C
Structures in c++
Structures
Lecture18 structurein c.ppt
Structure c
C programing -Structure

What's hot (19)

PPTX
Structure in C language
PPTX
Structure in C
PPT
Structure in c
PPTX
Unit 9. Structure and Unions
PPTX
Presentation on c programing satcture
PPTX
Programming in C session 3
PPTX
Structures in c language
PPT
PPT
Structure in c
PPT
Structures
PPTX
Structure & Union in C++
PPTX
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
DOCX
Unit 4 qba
PDF
Unit 4 qba
PPT
Unit4 C
PPTX
Structure & union
PPTX
Structure in c#
PDF
C structure and union
Structure in C language
Structure in C
Structure in c
Unit 9. Structure and Unions
Presentation on c programing satcture
Programming in C session 3
Structures in c language
Structure in c
Structures
Structure & Union in C++
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Unit 4 qba
Unit 4 qba
Unit4 C
Structure & union
Structure in c#
C structure and union
Ad

Similar to When to use a structure vs classes in c++ (20)

PPTX
Marco Mancuso - Data Context Interaction
PPTX
Advanced Topics on Database - Unit-2 AU17
PPT
ORM Concepts and JPA 2.0 Specifications
PDF
Tcs NQTExam technical questions
PPTX
Unit-5.1.pptx programing in c language lesson 5
PPTX
Concepts for Object Oriented Databases.ppt
PPTX
PPL, OQL & oodbms
ODP
Data massage! databases scaled from one to one million nodes (ulf wendel)
PDF
01 objective-c session 1
PDF
80410172053.pdf
PPTX
Fundamentals of OOP (Object Oriented Programming)
PDF
Chapter – 2 Data Models.pdf
PPTX
Dynamic Memory & Linked Lists
PPTX
Cowboy way to iOS 8Presentation1
PPT
Ooad ch 2
PPTX
MIT302 Lesson 2_Advanced Database Systems.pptx
PPT
Chapter 02 The Object Model_Software E.ppt
PPTX
Data Structures & Algorithms
PPTX
C++ training
DOC
Structures unions
Marco Mancuso - Data Context Interaction
Advanced Topics on Database - Unit-2 AU17
ORM Concepts and JPA 2.0 Specifications
Tcs NQTExam technical questions
Unit-5.1.pptx programing in c language lesson 5
Concepts for Object Oriented Databases.ppt
PPL, OQL & oodbms
Data massage! databases scaled from one to one million nodes (ulf wendel)
01 objective-c session 1
80410172053.pdf
Fundamentals of OOP (Object Oriented Programming)
Chapter – 2 Data Models.pdf
Dynamic Memory & Linked Lists
Cowboy way to iOS 8Presentation1
Ooad ch 2
MIT302 Lesson 2_Advanced Database Systems.pptx
Chapter 02 The Object Model_Software E.ppt
Data Structures & Algorithms
C++ training
Structures unions
Ad

More from Naman Kumar (12)

PPTX
Probability
PPTX
Conic Sections- Circle, Parabola, Ellipse, Hyperbola
PPTX
Research & Development - Major Organisations of India , R&D Importance and Role
PPT
The life of albert einstein ppt
PDF
Fifteen painted cards from a vampire tarot
PDF
Smoke and mirrors by neil gaiman
TXT
Windows 8 keys and acivator ..
PDF
Dictionary of chemical formulas
PDF
Reactivity Series Of Metals
PDF
Periodic table of elements - ( Science )
DOC
Sikhism
PDF
The designer of the indian national flag
Probability
Conic Sections- Circle, Parabola, Ellipse, Hyperbola
Research & Development - Major Organisations of India , R&D Importance and Role
The life of albert einstein ppt
Fifteen painted cards from a vampire tarot
Smoke and mirrors by neil gaiman
Windows 8 keys and acivator ..
Dictionary of chemical formulas
Reactivity Series Of Metals
Periodic table of elements - ( Science )
Sikhism
The designer of the indian national flag

Recently uploaded (20)

PDF
Phytochemical Investigation of Miliusa longipes.pdf
PDF
Formation of Supersonic Turbulence in the Primordial Star-forming Cloud
PPTX
ECG_Course_Presentation د.محمد صقران ppt
PPT
The World of Physical Science, • Labs: Safety Simulation, Measurement Practice
PPTX
ognitive-behavioral therapy, mindfulness-based approaches, coping skills trai...
PPTX
Introduction to Cardiovascular system_structure and functions-1
PPTX
DRUG THERAPY FOR SHOCK gjjjgfhhhhh.pptx.
PPTX
Taita Taveta Laboratory Technician Workshop Presentation.pptx
PDF
HPLC-PPT.docx high performance liquid chromatography
PPTX
ANEMIA WITH LEUKOPENIA MDS 07_25.pptx htggtftgt fredrctvg
PPTX
neck nodes and dissection types and lymph nodes levels
PPTX
INTRODUCTION TO EVS | Concept of sustainability
PDF
CAPERS-LRD-z9:AGas-enshroudedLittleRedDotHostingaBroad-lineActive GalacticNuc...
PPT
POSITIONING IN OPERATION THEATRE ROOM.ppt
PDF
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
PDF
IFIT3 RNA-binding activity primores influenza A viruz infection and translati...
PPTX
GEN. BIO 1 - CELL TYPES & CELL MODIFICATIONS
PPTX
BIOMOLECULES PPT........................
PPTX
Derivatives of integument scales, beaks, horns,.pptx
PPTX
2. Earth - The Living Planet Module 2ELS
Phytochemical Investigation of Miliusa longipes.pdf
Formation of Supersonic Turbulence in the Primordial Star-forming Cloud
ECG_Course_Presentation د.محمد صقران ppt
The World of Physical Science, • Labs: Safety Simulation, Measurement Practice
ognitive-behavioral therapy, mindfulness-based approaches, coping skills trai...
Introduction to Cardiovascular system_structure and functions-1
DRUG THERAPY FOR SHOCK gjjjgfhhhhh.pptx.
Taita Taveta Laboratory Technician Workshop Presentation.pptx
HPLC-PPT.docx high performance liquid chromatography
ANEMIA WITH LEUKOPENIA MDS 07_25.pptx htggtftgt fredrctvg
neck nodes and dissection types and lymph nodes levels
INTRODUCTION TO EVS | Concept of sustainability
CAPERS-LRD-z9:AGas-enshroudedLittleRedDotHostingaBroad-lineActive GalacticNuc...
POSITIONING IN OPERATION THEATRE ROOM.ppt
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
IFIT3 RNA-binding activity primores influenza A viruz infection and translati...
GEN. BIO 1 - CELL TYPES & CELL MODIFICATIONS
BIOMOLECULES PPT........................
Derivatives of integument scales, beaks, horns,.pptx
2. Earth - The Living Planet Module 2ELS

When to use a structure vs classes in c++

  • 2. #1: When to Use a struct vs Class #6: How would you count the occurrences of a string within a string? #11: Encrypt/Decrypt a String in .NET #16: How do I Make a Texbox that Only Accepts Numbers? #2: How Does One Parse XML Files? #7: How to Check if a Number is a Power of 2 #12: How do I Get the Index of the Current Iteration of a foreach Loop? #17: How do I Round a Decimal Value to 2 Places for Output? #3: What is the Difference between String and string #8: C# Loop – break vs continue #13: How to Get My Own IP address in C# #18: Remove Duplicates from an Array #4: How do I get the Application’s Path in a C# Console App? #9: Difference Between abstract and virtual functions #14: How do I Calculate Someone’s Age in C#? #19: How do I Sort a Dictionary by Value? #5: Calling base Constructor in C# #10: Difference Between ref and out Keywords #15: How do I get the String Value of an enum? #20: How Can I Return Multiple Values From a Function in C#?
  • 3. • structs are value types that can contain data and functions • structs are value types and do not require heap allocation. • structs directly store their data in the struct, classes store a reference to a dynamically allocated object. • structs are useful for small data structures • structs can affect performance • Constructors are invoked with the new operator, but that does not allocate memory on the heap • A struct constructor simply returns the struct value itself (typically in a temporary location on the stack), and this value is then copied as necessary
  • 4. • With classes, multiple variables may have a reference to the same object • It is possible for operations on one variable to affect the object referenced by the other variable. • With structs, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other. • structs do not support user-specified inheritance, and they implicitly inherit from type object