Understanding Structs in C++

Understanding Structs in C++

12th Grade

15 Qs

quiz-placeholder

Similar activities

Data Structures

Data Structures

9th - 12th Grade

10 Qs

quiz - structs

quiz - structs

9th - 12th Grade

11 Qs

Python elif and Nested if

Python elif and Nested if

12th Grade

15 Qs

Technical Quiz R2

Technical Quiz R2

12th Grade

15 Qs

XII Computer Datastructures 2023

XII Computer Datastructures 2023

9th - 12th Grade

20 Qs

Premiere Pro Panels

Premiere Pro Panels

9th - 12th Grade

14 Qs

7. PYTHON FUNCTIONS - 3

7. PYTHON FUNCTIONS - 3

12th Grade

10 Qs

C - Language Quiz

C - Language Quiz

12th Grade

15 Qs

Understanding Structs in C++

Understanding Structs in C++

Assessment

Quiz

Computers

12th Grade

Medium

Created by

Adnan Ahmad

Used 2+ times

FREE Resource

15 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct syntax to define a struct in C++?

struct { memberName: dataType; } StructName;

struct StructName: dataType memberName;

StructName struct { memberName dataType; };

struct StructName { dataType memberName; };

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How can you access a member of a struct in C++?

Access members using the colon operator (::).

Members can only be accessed through a function.

Use the dot operator (.) or arrow operator (->) to access members of a struct.

Use the semicolon (;) to access members of a struct.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Can a struct in C++ contain member functions? If so, how?

No, a struct in C++ cannot contain member functions.

Only classes can have member functions in C++.

Yes, a struct in C++ can contain member functions.

Structs in C++ can only contain data members, not functions.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is a nested struct and how is it defined in C++?

A nested struct is a type of variable in C++.

A nested struct can only contain primitive data types.

A nested struct is defined outside of any other struct.

A nested struct is a struct defined within another struct in C++. It is defined by placing the inner struct declaration inside the outer struct.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you declare an array of structs in C++?

struct MyStruct { int a; float b; }; MyStruct myArray[10];

struct MyStruct[] myArray;

MyStruct myArray = new MyStruct[10];

MyStruct myArray(10);

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the difference between a struct and a class in C++?

Structs cannot have member functions; classes can.

Structs have public members by default; classes have private members by default.

Structs can inherit from other structs; classes cannot.

Classes are used for data only; structs are used for functions only.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you pass a struct to a function in C++?

You must always pass a struct by reference.

You can pass a struct to a function in C++ by value, by reference, or by pointer.

Structs cannot be passed to functions in C++.

You can only pass a struct by value.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?