Programming Challenge #9: CYBORG DATA TYPE SIZES | Starting Out With C++ | Chapter 2

Programming Challenge #9: CYBORG DATA TYPE SIZES | Starting Out With C++ | Chapter 2 comes from the “Review Questions and Exercises” section at the end of Chapter 2 in Tony Gaddis’ book Starting Out With C++ : From Control Structures Through Objects/8th Edition.

>_ The Problem

You have been given a job as a programmer on a Cyborg supercomputer. In order to accomplish some calculations, you need to know how many bytes the following data types use: char, int, float, and double.

You don’t have any manuals, so you can’t look this information up. Write a C++ program that will determine the amount of memory used by these types and display the information on the screen.

>_ The Solution

#include <iostream>
using namespace std;
int main()
    cout << endl;
    cout << "A char uses " << sizeof(char) << " byte." << endl;
    cout << "An int uses " << sizeof(int) << " bytes. " << endl;
    cout << "A float uses " << sizeof(float) << " bytes. " << endl;
    cout << "A double uses " << sizeof(double) << " bytes. " << endl;
    cout << endl;

    return 0;

Topics Used:

2.1  The Parts of a C++ Program

CONCEPT: C++ programs have parts and components that serve specific purposes.

2.2  The cout Object

CONCEPT: Use the cout object to display information on the computer’s screen.

2.3  The #include Directive

CONCEPT: The #include directive causes the contents of another file to be inserted into the program.

2.6  Integer Data Types

CONCEPT: There are many different types of data. Variables are classified according to their data type, which determines the kind of information that may be stored in them. Integer variables can only hold whole numbers.

2.7  The char Data Type

2.9  Floating-Point Data Types

CONCEPT: Floating-point data types are used to define variables that can hold real numbers.

2.11 Determining the Size of a Data Type

CONCEPT: The sizeof operator may be used to determine the size of a data type on any system.

2.13 Scope

CONCEPT: A variable’s scope is the part of the program that has access to the variable.

2.17 Programming Style

CONCEPT: Programming style refers to the way a programmer uses identifiers, spaces, tabs, blank lines, and punctuation characters to visually arrange a program’s source code. These are some, but not all, of the elements of programming style.

That’s it for Programming Challenge #9: CYBORG DATA TYPE SIZES | Starting Out With C++ | Chapter 2!

Thank you for taking interest in this post. I hope it was helpful for you as much as it helped me along my journey in learning to code!

Also Check Out:

Category: Starting Out With C++ | Chapter 2 | Programming Challenge Solutions

Leave a Reply