Introduction to C++

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

True

A variable of the char data type can hold only one character at a time.

True

All escape sequences just need one byte of storage.

Numeric and character

Although C++ offers many data types, in the very broadest sense there are only two. What are the two?

True

Although the char data type is used for storing characters, it is actually an integer data type.

True

Char data types usually use one bite of data.

True

Characters normally occupy a single byte of memory.

True

Even though the newline character \n is represented by 2 characters, it is 1 byte.

True

Every C++ program must have a function called main.

Variable names

Give an example of an identifier.

Int length, width;

Give an example of defining two variable definitions of the same type on a single line of code.

When you need to store ages or weight.

Give two situations you might use an unsigned data type.

True

Printable characters are internally represented by numeric codes. Most computers use ASCII codes for this purpose.

True

Quotation marks are not stored with string. They are simply a way of marking the beginning and end of the string in your source code.

True

Some programmers use the underscore character to separate words in a variable name.

True

Strings are a series of characters stored in consecutive memory locations that can be any length long.

True

Strings are consecutive sequences of characters that occupy consecutive bytes of memory.

True

Strings are intended for humans to read. They are to be printed on computer screens or papers. Numbers, however, are intended primarily for mathematical operations.

True

The integer 5 and string literal "5" are not the same thing.

True

The size of a variable is the number of bytes of memory it uses.

True

The size of the different type of integers is dependent on the type of system you are using.

True

Variable definitions can appear in any part of a program.

True

Variables are classified according to their data type, which determines what kind of information that may be stored in them.

A zero (0).

What ASCII code is appended to the end of a string literal to know it has reached the end of the string?

They called the string insertion operator. They are used to send the text in the quotation marks on the right side to the cout stream object.

What are the << symbols called and used for in the following code? cout << "Programming is great fun!";

To assign a value to a variable and to display something on the screen.

What are the two most common way to use a literal?

Variables represent storage locations in the computer's memory. They allow you to work with data in the computer's memory.

What are variables?

The largest and smallest numbers that may be stored in the variable. How much memory the variable uses. Whether the variable stores signed or unsigned numbers. The number of decimal places of precision the variable has.

What are your primary considerations for selecting a numeric data type?

Numbers with decimals.

What do floating points store?

Whole numbers.

What do integers store?

The letter L

What do you place at the end of a number if you want to force an integer literal to be stored as a long integer?

This is called a preprocessor directive. The preprocessor reads your program before it is compiled and only executes those lines beginning with the # symbol.A program that "sets up" your source code for the compiler.

What does "#" do?

It marks the beginning of a comment. The compiler ignores everything from the double slash to the end of the line. Comments help explain what's going on in a program.

What does "//" do?

Integer. Indicates that the function sends an integer value back to the operating system when it is finished executing.

What does "int" mean in the following function? int main()

Marks the ending of a complete statement.

What does a ";" mean in C++

It marks the end of a string.

What does a null terminator do?

Console output

What does cout stand for?

Ends a line and starts a new one.

What does endl; do?

int number; Integer

What does int in the following code stand for?

Causes the preprocessor to include the contents of another file in the program. The name inside the brackets is the name of the file that is to be included.

What does the #include <header> directive indicate?

It allows a C++ program to display output on the screen and read input from the keyboard.

What does the #include <iostream> directive do?

number = 100; The statement assigns the literal value 100 to the variable number.

What does the following code do?

It displays the string literal "Welcome to my program." to the screen.

What does the following code do? cout << "Welcome to my program." << endl;

Marks the beginning of a function.

What does the following code do? int main()

It is called the newline escape sequence. It ends a line and starts a new one.

What is \n do and what is it called?

Left-brace, or an opening brace. It is associated with the beginning of a function.

What is a "{"?

Closing brace. Marks the end of a function.

What is a "}"?

A group of one or more programming statements that collectively has a name.

What is a function?

A literal is a piece of data that is written directly into a program's code.

What is a literal?

A null character.

What is a null terminator also called?

A program that you can read and understand what is happening. This happens by choosing variable names that indicate what the variable is used for.

What is a self-documenting program?

Main

What is a the name of the following function? int main()

It tells the compiler the variables name and the type of data it will hold.

What is a variable definition?

A programmer-defined name that represents some elements of a program.

What is an identifier?

A stream manipulator.

What is endl; called?

The equal sign copies the value 5 into the variable "number".

What is happening in the following code? number = 5;

Header file

What is iostream called in the following code? #include <iostream>

To store individual characters.

What is the char data type used for?

It is being used as an operator that copies "5" into the variable "number".

What is the equal sign doing in the following code? number = 5;

An assignment. It is copying the data on the right side of the equal sign into the variable on the left.

What is the following line of code called? number = 5;

String lateral or string constant.

What is the group of characters inside the quotation marks in the following code called? cout << "Programming is great fun!";

To display text to the monitor.

What is the purpose of cout?

int number; Number

What is the variable's name in the following code?

You cannot assign a string literal to the char data type because it can only store one character. The string literal "A" is 2 because not only is it going to store the character A, it is going to store the null terminator at the end of it marking the end of the string.

What is wrong with the following code? char letter; letter = "A";

Input-Output stream library

What library is cout/cin from?

True

When a character is stored in memory, it is actually the numeric code that is stored. When the computer is instructed to print the value on the screen, it displays the character that corresponds with the numeric code.

When you know your program will not encounter negative values.

When should you use an unsigned data type?

True

When you put quotation marks around something, it becomes a string literal.

True

When you send a variable name to cout it prints the variable's contents.

After the function named main.

Where does a program start?

Because they can only hold one character. Even if the string has one character, double quotation marks are used and not single quotation marks.

Why can't char variables be used to store strings?

Because it requires less typing.

Why do many programmer like using \n rather than endl;?

To improve user readability.

Why is the O in the following code capitalized? int itemsOrdered;

Because cout/cin is not part of the "core" of C++ language.

Why must the header iostream be used at the beginning of a program?

True

You can define several variables of the same type, separating their names with commas, on the same line of code.

False

You can have spaces in variable names.

True

You cannot perform math on strings.

True

You must have a closing brace for every opening brace in your program.

True

You must have a definition for every variable you intend to use in a program.

True

You should always choose variable names that indicate what the variables are used for.

String literals can contain more than one character and are enclosed in double quotation marks. Char literals can only hold one character and are enclosed in single quotation marks.

How are string literals and char literals different?

It adds an extra bite to the end of the string to let the computer know that it has reached the end of a string.

How does the computer know when it has reached the end of a string?

| A | \0 | 2

How would a computer store a string literal "A"? How many bytes is it?

| A | 1

How would a computer store char a? How many bytes is it?

| S | e | b | a | s | t | I | a | n| \0 |

How would the string literal Sabastian be stored?

\n

Identify the newline escape sequence.

True

If a numeric literal is an integer and it fits within the range of an int, then the numeric literal is treated as an int.

True

If you want to use the \n new line escape sequence, you must inside it in the quotation marks of a string literal.

True

In C++, character literals are enclosed in single quotation marks.

True

Integer variables can only hold whole numbers.

No. Variable names cannot begin with a digit.

Is 3dGraph a legal identifier?

Yes

Is June1998 a legal identifier?

No. Variable names can only include letters, numbers, or underscores.

Is Mixture#3 a legal identifier?

Yes.

Is _employee_num a legal identifier?

Yes

Is dayOfWeek a legal identifier?

True

It is easier to combine variable definitions on the same line if they are the same type.

False

ItemsOrdered is the same thing as itemsordered.

\n New line - Causes the cursor to go to the next line for subsequent printing. \t Horizontal tab - Causes the cursor to skip over to the next tab stop. \a Alarm - Causes the computer to beep. \b Backspace - Causes the cursor to back up, or move left one position \r Return - Causes the cursor to go to the beginning of the current line, not the next line. \\ Backslash - Causes a backslash to be printed. \' Causes a single quotation mark to be printed. \" Causes a double quotation mark to be printed.

List and describe common escape sequences.

First character must be a letter a-z or an underscore. After the first character, you can use letters a-z, the digits 0-9, or underscores. Upper and lowercase characters are distinct.

List the rules that must be followed when naming an identifier.

True

Literals are also called constants.

Integer and floating point.

Numeric data types are broken down into what to categories?


संबंधित स्टडी सेट्स

Chapter 12 = Disaster Recovery and Incident Response

View Set

Topic 15: Garden Planting and Planning

View Set

Chemistry: Naming Ionic Compounds with Polyatomic Ions

View Set

Chapter 2 Financial Statements, Taxes and Cash Flow

View Set