CS 135 - Chapter 2
True/False: The c++ language requires that you give variables names that indicate what the variables are used for
False. It is not a requirement, just a recommendation as it makes code easier to understand.
True/False: A variable called "average" should be declared as an integer data type because it will probably hold data that contains decimal places.
False - it should be stored as a float or double
This function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires.
sizeof
How many bytes of memory will the following string literal occupy? "William"
8
Rules for a legal identifier:
1. First character must be a letter or underscore 2. after first character, you can use letters, numbers, or underscores 3. Uppercase and lowercase letters are distinct
What is a function?
A group of one or more statements that are under one name.
What is a piece of data written into a program's code?
A literal
If you want an integer literal to be treated as a long long int, you can put ___ at the end of the number.
LL
True/False: Escape sequences are always stored internally as a sing character
True. Escape sequences (\n \t \r etc) are stored as a single character in memory
In programming terms, a group of characters inside a set of quotation marks is called a:
String literal
Which data type typically requires only one byte of storage?
char
What does cout stand for
console output. This is classified as a stream output
You must have a ___________ for every variable you intend to use in a program.
definition
What are floating point constants normally stored in memory as?
doubles
What is a Boolean?
expressions that have either a true or false value
What does = mean in c++?
it is an assignment operator
The float data type is considered ___ precision, and the double data type is considered ___ precision.
single, double
What is C++'s built in data type for storing strings of characters?
string -#include<string> is the preprocessor directive for the string class
Explain the null terminator
It marks the end of a string. This means strings have one extra byte. i.e., "A" is stored as [A \0]
If you use a C++ key word as an identifier, your program will:
Not compile
What is the value of cookies after the execution of the following statements? int number = 38, children = 4, cookies; cookies = number % children;
cookies = 2; (find the remainder)
Explain #include<iostream>
# is the preprocesser directive -include causes the preprocessor to include a header file in the program -iostream is the name of the header file. it contains code that helps the program read input from the keyboard and display it on screen.
What are the functions of the following escape sequences: \n \b \t \r \a
-newline -backspace -horizontal tab -return -alarm
Which of the following would be an illegal variable name? _employee_num 3dGraph itemsorderedforthemonth dayOfWeek June1997
3dGraph - cannot start with a number
What does the keyword auto do
tells the compiler to determine data type from the initialization data value