Search Header Logo

Understanding Structs in C++

Authored by Adnan Ahmad

Computers

12th Grade

Used 3+ times

Understanding Structs in C++
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

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.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?