array of characters.
Strings are stored in arrays of characters. The end of a string is indicated by an end of
string character (‘\0’). Because strings use this marker strings can be any length up to the
size of the array they are stored in (—1 for the end of string marker).
6. Why must we use std::strcpy to assign one C style string to another?
C++ does not have an array assignment operator, so it’s impossible to assign one
character array to another.
7. We define a character array whose job is to hold a string. What is the difference between the size
of the array and the length of a C style string?
The size of the array is fixed and set to the size declared at compile time. The length of a
string can change depending on where we place the end of string character.
8. Can the size of any array change during the execution of a program?
No.
9. Can the length of a string variable change during the execution of a program?
Yes.
10. What happens if you try to read a C++ style string using std::cin and the >> operator? (Try
it!) What about the C style strings?
The input line, up to the first space or other whitespace character, is read into the string.
11. How many elements are allocated for the multiple dimension array:
int four_dimensions[25][86][48][96];
Bonus question: Why will you probably never see a declaration like this in a real
program?
This array defines 3,863,808 elements. (25*86*48*96) On a machine that uses 4 bytes
per integer that’s 15,455,232 bytes or 15MB. That’s a lot of memory for a single array.
12. Define the following:
long int short int unsigned signed
float double register auto
volatile const reference extern
long int a signed integer that may hold more data than an ordinary integer .
short int a signed integer that may hold less data than an ordinary integer .
Page 17
unsigned variable that may hold only positive value. By sacrificing the sign bit, the numbe r
can hold twice as many positive values.
signed a number that may hold positive and negative values. Since this is the default fo r
integers and floating point variables, it is rarely used.
float a variable type that can hold real or fractional values .
double a real variable type that has more range and precision than “float.”
register a suggestion from the programmer to the compiler indicating that this variable is
used a lot so it would be a good idea to put it in a machine register.
auto a variable that is automatically allocated from the stack .
Practical C++ Programming by manish baranwal
Start from the beginning
