Introduction to Structures and Classes

Introduction to Structures and Classes

Ram, now has a good clarity on Primitive Datatypes, now he’s learning User defined datatypes. While doing so he encountered Structures and Classes. Ram has no clue why does anyone have to define their own datatype when they have different primitive datatypes which are already defined.

No alt text provided for this image
Why do we need custom datatypes...?

Again he started to watch reels until he remembered that the next day is his little sister’s birthday. He immediately got off the study table and started to write on paper all the different food and things his sister is found of. He has filled the paper with different Chocolates and sweets.


He immediately bought everything he need for surprise, But he don’t want to give these all just like that. It will be a surprise if she sees all her favourite things at a time. Now he has started to prepare a big box with cardboard sheets and made sections in the box to fit all the things he bought

No alt text provided for this image
Custom surprise box prepared by Ram

He finally prepared a custom box, filled it with all the surprise gifts and chocolates and some cash in a different slot in box and wrapped it tight as a beautiful present.

Next day after all the arrangements for the birthday celebrations has begun, he presented the box he prepared for his sister.

No alt text provided for this image
Ram gifted his sister

Sister has opened the box and got surprised to see all her favourite things in one single box and was very happy with the present and the efforts made by her brother to prepare this present with his own hands.

No alt text provided for this image
Surprise Gift

Ram then understood that no one else know what can be a custom present to his sister other than him, so he prepared a custom gift of all her likings. And he thought he can just use this box idea with different things on next birthday.

Later that night he understood that, yes we indeed need a custom datatype to hold all our required variables regarding a particular thing like height, weight and grade of a student in a custom student structure and then declare any number of students with this custom datatype and every student has build in variables of height, weight and grade.

Structure Syntax:

No alt text provided for this image
Structure Syntax

Now he understood everything was fine with the Giftbox but he has a bit of discomfort that everyone at the party has witnessed the money he gifted in the Gift box, and he thought to upgrade the cardboard box to a new level where some slots are just known to his sister so that she can only view that slots when she’s in private place and grab the cash and personal photos rather then displaying it to everyone while opening the box.

No alt text provided for this image
Box with private & protected slots


Now in the same box he inserted some secret chambers and gifted it. Now Ram is super happy that some sections in his custom box are private and some are public.

Ram got to understand this as Class, where some variables are publicly declared, some are private and some are protected. All these need to be accessed by creating an instance of this class.

Class Syntax:

No alt text provided for this image
Class syntax

Read about classes and structures more in here:


要查看或添加评论,请登录

Putta Hemanth Kumar的更多文章

  • Merge Sort Technique

    Merge Sort Technique

    Ram is determined to conquer the formidable Merge Sort, a sorting algorithm that had always been a bit of a puzzle for…

  • Binary Search Algorithm

    Binary Search Algorithm

    Ram, who is passionate about coding had managed to learn all the fancy data structures, much to the amazement of his…

    2 条评论
  • Introduction to Stacks

    Introduction to Stacks

    Ram, had recently completed his studies on arrays and linked lists, and now he was ready to embark on a new data…

  • Introduction to Linkedlist

    Introduction to Linkedlist

    Ram has completed his learning and practice in array data structure, He understood all the pros and cons of arrays, Now…

  • Introduction to Array Datastructure

    Introduction to Array Datastructure

    Ram understands very well that in order to tackle any programming challenge, he must learn about data structures and…

  • A brief Introduction to DSA

    A brief Introduction to DSA

    Ram, who is knowledgeable about various programming datatypes and functions, wanted to learn more about data structures…

  • Introduction to Functions

    Introduction to Functions

    Ram, has learned and experienced what are primitive datatypes and what are user defined datatypes. Now he tries to…

  • Introduction to Primary Data Types

    Introduction to Primary Data Types

    Ram, a curious student who wants to learn DSA and started with primary datatypes. Ram is confused after looking at…

    3 条评论

社区洞察

其他会员也浏览了