Arithmetic Operators Flashcards
To understand Arithmetic Operators in C++
What symbol is used for the addition operator?
The + sign (the plus sign)
Why would we use the addition operator?
We use the addition operator to add two variables together or to figure out large addition problems.
What happens if you add an integer of to a double?
You would result in a double answer, however if the addition ends up with a .0 at the end. It wouldn’t show and it would result in an int answer.
For example,
cout «_space;7 + 3.14; prints 10.14
however
cout «_space;7.0 + 3; prints 10
also it would remove irrelevant/additional 0s if available
cout «_space;7.0 + 3.00140000; prints 10.0014
What is the cout command considered to be?
It is considered to be non-specific because you can use the same syntax for all of your printing needs (e.g. cout «_space;1; cout «_space;“Hello”;, and cout «_space;true;). However, for printing certain numbers, it is not always clear if what’s printed is an int or a double.
What is printf()? What is different between it and cout?
printf() originates from the C language and, unlike the cout command, it is considered to be specific. This means that you must specify what type of data you want to print before you can use the command successfully.
When using the printf() command. What does \n do?
The \n in the printf() command creates a newline character and it causes the variables to be printed one below the other.
When using the printf() command. What is the %d for?
The %d tells the system to print an integer.
When using the printf() command. What is the %f for?
The %f tells the system to print a floating point number.
What is the difference between the %d and %f?
The %d orders the system to print an integer while %f orders to print a floating point number.
What happens if you use an incorrect specifier?
If an incorrect specifier is used, you will recieve an error message.
How many zeros (after the decimal point) does the floating point number contains?
Floating point numbers contain six zeros after the decimal point if they are printed using printf().
What’s the difference between cout and printf()?
Unless you want to be specific with how your data is printed, you should always default to using cout. Only use printf() when formatting is important.
What does it mean to increment a variable?
Incrementing a variable means to increase the value of a variable by a set amount. The most common incrementation is when a variable increments itself by the value of 1.
What is the incrementating equation?
The incrementating equation is a = a +1;
The new value of a is assigned the old value of a plus 1
What is string concatenation?
String concatenation is the act of combining two strings together. This is done with the + operator.