🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

UNIT 2 CS - 15 class & obj, constructor & destructor.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Document Details

SelfSatisfactionLongBeach4894

Uploaded by SelfSatisfactionLongBeach4894

Rajkot

Tags

C++ programming object-oriented programming constructors programming

Full Transcript

1 CS-15 C++ and Object Oriented Programming Unit – 2 Presented By : Dhruvita Savaliya Classes and Objects, Constructor and Destructor 2 ...

1 CS-15 C++ and Object Oriented Programming Unit – 2 Presented By : Dhruvita Savaliya Classes and Objects, Constructor and Destructor 2 3 C Structure revised : Structure in an User Defined Data Type. A Structure contains a number of data types group together. These data types may or may not be of same type. For example, an entity Student may have its name (string), roll number (int), marks (float). Syntax of creating a structure : struct [structure tag] { member definition/declaration ; member definition/declaration ;... member definition/declaration ; } [one or more structure variables]; 4 How to declare structure variables/object variable? Before semicolon at structure terminates. At global declaration section (Global Scope). Inside the main function (Local Scope). Syntax : struct ,[obj2,3,4….]; Accessing Structure Members To access any member of a structure, we use the member access operator (.). The member access operator is coded as a period between the structure variable name and the structure member that we wish to access. You would use struct keyword to define variables of structure type. Syntax : structure variable_name.structure_member_name 5 Example : // A variable declaration like basic data types struct Point { int x, y; }p1; //before semicolon Struct Point p2 //global declaration void main() { struct Point p3; // Local Variable -> The variable p3 is declared like a normal variable p3.x=43; p3.y=65; struct Point p4={10,20}; cout

Use Quizgecko on...
Browser
Browser