Search Header Logo

chapter 4 -Structures

Authored by MAHANI BINTI ZAKARIA (POLIMAS)

Information Technology (IT)

University

Used 7+ times

chapter 4 -Structures
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following best describes a structure in C++?

A group of similar data types stored in a single variable

A data type used to store characters only

A user-defined data type that groups variables of different types

A pointer that stores memory addresses

Answer explanation

A structure (struct) in C++ allows grouping of variables of different data types under a single name. This is useful when representing real-world entities such as a student, which may have name (string), age (int), and grade (char).

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

What is the key difference between an array and a structure?

Arrays store values of different types; structures store only one type

Arrays are user-defined; structures are built-in

Arrays store values of the same type; structures can store values of different types

Structures use more memory than arrays

Answer explanation

Arrays in C++ are used to store multiple values of the same data type, whereas structures can combine values of different data types (e.g., int, char, string) under one name.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which syntax correctly declares a structure in C++?

structure Student { string name; int age; };

struct Student = { string name; int age; };

struct Student { string name; int age; };

Student structure { string name; int age; };

Answer explanation

The correct keyword to declare a structure is struct, followed by the structure name and a block containing the members.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you access a member of a structure variable named student1 with a member name?

student1->name;

student1:name;

student1.name;

student1->name();

Answer explanation

When using a structure variable (not a pointer), use the dot operator . to access its members. The arrow operator -> is used only with structure pointers.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What happens when you define a structure but do not create a variable of it?

The program will run with warnings

The compiler ignores the structure

It reserves memory for the structure

No memory is allocated until a structure variable is created

Answer explanation

Defining a structure only creates a new data type. Memory is only allocated when you declare variables of that structure type.

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?