Question: rrays: Character Arrays vs . cStrings - First, guess the following output. Write down what you think the output is . - Then enter the

rrays: Character Arrays vs. cStrings
- First, guess the following output. Write down what you think the output is.
- Then enter the code and run the program to see if you are correct.
#include
#include
#include
using namespace std;
int main()
{
double floatArray[7]={1.01,2.02,3.33,4.044,5.5,6.06,7.77};
cout <<"(A). The floatArray output using - cout <<
\t"
<< floatArray <<
";
//===============================================
cout <<"(B). Output of the floatArray values - using a for loop
\t";
for (int i =0; i <7; i++)
cout << floatArray[i]<<'\t';
cout << endl << endl;
//===============================================
int intArray[8]={1,2,3,4,5,6,7,8};
cout <<"(C). Output of the intArray values - using cout <<
\t"
<< intArray <<"
";
//===============================================
cout <<"(D). Output of the intArray values using a for loop
\t";
for (int i =0; i <7; i++)
cout << intArray[i]<<'\t';
cout << endl << endl;
//==============================================
char cStringArray[8];
strcpy(cStringArray, "Tom Lee");
cout <<"(E). Output of strcpy assignment to cStringArray - using cout <<
\t";
for (int i =0; i <7; i++)
cout << cStringArray[i];
cout << endl << endl;
//===============================================
Page 2 of 7
cout <<"(F). Enter a 7-character name to be read by cin.getline(): ";
cin.getline(cStringArray,7);
cout <<"
\tOutput after entering 7 letters - output by cout <<:
\t";
cout << cStringArray << endl;
//===============================================
//===============================================
char yourName[8];
strcpy(yourName, "Tom Lee");
cout <<"(G). What is output when using:
\t"
<<"strcpy(yourName,\"Tom Lee\"); - and cout << yourName[2]:
\t";
cout << yourName[2]<< endl;
//===============================================
char myName[8]= "Tom Lee";
cout <<"(H). What is output when using:
\t"
<< "char myName [8]=\"Bob Lee\"; - and cout << myName[2]:
\t";
cout << myName[2]<< endl;
//===============================================
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!