CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →

KwickAcademy Cyber Safety and Ethics · 7 min · free

Structures, Typedef and Enumerated Data Types in C++

7 min4 KwickClipsFull text belowFree
Kajal Ma'am (MCA), teaching since 2004Remembered in this browser

A C++ structure groups different types under one name; typedef gives a type a new name; enum names whole number constants from 0.

Follows the syllabus of: GSEB Std 10 Computer Studies, GSEB Std 12 Computer Studies, NIOS Senior Secondary Computer Science (330)

On screen in this lesson

Why do we need structures?

An array holds many values of the same type
A student record mixes types: int, float, char
A structure groups different types under one name
It is a user-defined data type

typedef: a nickname for a type

typedef gives an existing type a new name
Syntax: typedef existing_type new_name;
It does not create a new type
Modern C++ also allows: using Mobile = long long;

enum rules

Values start at 0 unless you set them
Each next name is one more than the last
Two enums in one scope cannot reuse a name
enum class keeps names inside: Color::Red

Structure vs class

Pointstructclass
Default accesspublicprivate
Can have functionsYesYes
Usual usePlain dataData + behaviour
Keywordstructclass

Quick recap

struct groups different types; end it with };
Use the dot operator to reach members
typedef gives an existing type a new name
enum names whole number constants from 0
struct members are public; class members private

Quick answers

What is the only real difference between struct and class?

Default access: struct is public, class is private.

In enum Medal { GOLD = 1, SILVER, BRONZE }, what is BRONZE?

3.

KwickClips from this lesson

Short clips, one idea each. Good for revision the night before.

The full lesson, in text

Hello students, welcome to Kwickprep. A student has a roll number, marks and a grade. Can one variable hold all three together? Yes, with a structure! Today we learn structures, typedef, enumerated types, and the one small difference between a structure and a class.

First, why do we need a structure? An array can hold many values, but all of the same type. A student record mixes types, like a whole number roll, decimal marks and a letter grade. A structure groups values of different types under one name. Because we create it ourselves, it is called a user defined data type.

We define a structure with the keyword struct, followed by its name. Inside the curly braces, we list its members. A member is one variable inside the structure. Here Student has three members: roll, marks and grade. Notice the semicolon after the closing brace, which students often forget. This only creates a design, like a blank form, so no memory is used yet.

Now we create a structure variable, which is like filling in the form. Student riya creates a variable named riya, and the values in curly braces fill the members in order. To reach a member, we use the dot operator, also called the member access operator. Riya dot roll is twelve, and riya dot grade is A. So it prints twelve A.

Members work like ordinary variables. Here is a canteen item called tea. Its price is ten rupees and the quantity is two. A friend joins, so we add one to the quantity using the dot operator. The bill, price times quantity, is thirty rupees.

We can also make an array of structures, one record for each student. The array cls, short for class, holds three students, each with a roll and marks. The loop visits each record and prints its marks with the dot operator. The output is seventy two, eighty five, sixty four. Pause and predict. What is cls of one dot roll? It is two, because indexes start at zero.

A structure can be passed to a function like any variable. Here Riya scored thirty, and the school gives three grace marks. The ampersand passes her record by reference, so the function changes the original. The output is thirty three. Without the ampersand, only a copy would change.

Next, typedef, which is short for type definition. Typedef gives an existing data type a new, easier name, like a nickname. You write typedef, then the existing type, then the new name, ending with a semicolon. It does not create a new type, so both names mean exactly the same thing. Modern C plus plus also lets you write the same idea with the keyword using.

A ten digit mobile number is too big for an int, which only goes up to about two hundred fourteen crore. So we need the type long long. Typedef names it Mobile, which also tells the reader what the value means. The program prints the full number.

An enumerated data type, made with the keyword enum, is a list of named whole number constants. It makes code easier to read, like writing Wednesday instead of the number two. The first name gets zero, and each next name gets one more. So Wednesday is two. Pause and predict. What is Friday? It is four, because Monday started at zero.

You can also choose the values yourself. Here gold is set to one. Silver has no value, so it takes one more than gold, which is two. Bronze then becomes three. So the output shows one, two, three.

Learn four rules about enum. The values start at zero unless you set them. Each next name is one more than the name before it. Two plain enums in the same scope cannot use the same name, such as Red, or the compiler reports an error. Modern C plus plus offers enum class, which keeps names inside, so you write Color, double colon, Red.

In C plus plus, a structure and a class are almost the same. The only real difference is default access. Members of a struct are public by default, so anyone can use them. Members of a class are private by default, so outside code cannot touch them. Both can have functions, which is not allowed in C. By habit, programmers use struct for plain data and class for data with behaviour.

Here are two types with the same member. For the struct, riya dot marks equals seventy two is allowed, because marks is public. For the class, the same line gives a compile error saying marks is private within this context. Write the word public, followed by a colon, inside the class, and both behave the same.

Some exams write a structure as a record in pseudocode. The idea is the same. Type starts the record, declare lists each field with its data type, and end type closes it. Then we declare a variable of that type and use the dot to reach a field.

Let us revise what we learned today. A structure groups values of different types, and its definition ends with a brace and a semicolon. The dot operator reaches each member. Typedef gives an existing type a new name, without making a new type. An enum names whole number constants, starting from zero. And struct members are public by default, while class members are private. Try making a structure for a cricket player with runs and wickets.

Courses that teach this

CourseUnit
CBSE Class 9 Information Technology (402)Introduction to IT-ITeS Industry
GSEB Std 10 Computer StudiesWeb Development with HTML
GSEB Std 12 Computer StudiesDesigning a Simple Website
Cambridge IGCSE Grade 10 Computer Science (0478)7. Algorithm Design and Problem-Solving
NIOS Senior Secondary Computer Science (330)Module 3: Programming in C++
Programming All levels CStructures, Unions, and Enums
Programming All levels C++C++ Foundations

Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.

Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

Want a plan that actually fits your board dates?

Ask Kajal Ma'am directly, 20+ years teaching computer science. Free demo class first, no payment.

Talk to Kajal Ma'am on WhatsApp

Or see the Class 12 Computer Science course →

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →