Shared Flashcard Set

Details

C++ Basics: Arrays
Introduction to Arrays
10
Computer Science
Undergraduate 1
04/04/2013

Additional Computer Science Flashcards

 


 

Cards

Term

Describe the following declaration:

 

int numbers[3] = {35, 235, 8};

Definition

 

An array of int data type with the size of 3 is declared and named numbers. The numbers 35, 235, 8 are assigned in that order.

Term

Identify the error if one exists.

 

char fullName[20] = {J, u, s, t, i, n};

Definition

Character arrays require single quotes around the letters.

 

char fullName[20] = {'J', 'u', 's', 't', 'i', 'n'};

Term
Describe a "c_string".
Definition
An array that holds char data type to create words.
Term

Will the following code compile:


int myarray[3] = {1, 2, 3, 4, 5};


Definition

 

 

No.

The size of the array is declared a 3, but 5 numbers are assigned to it. This will not compile.

Term

Will the following code compile?

 

int firstArray[3] = {1, 24, 64};

int secondArray[3];


secondArray = firstArray;

Definition

No. 

Arrays cannot be assigned to each other.

Term
How would you output the contents of an array?
Definition

Using a for-loop.


for (int i = 0; i < SIZE; i++)

{

      cout << firstArray[i] << endl;

}

Term

Spot the error in the code:

const int ROWS = 3;

const int COLS = 5;


int twoDimArray[ROWS][COLS];


for (int i = 0; i < ROWS; i++)

{

        for (int i = 0; i < COLS; i++)

        {

                  cin >>  twoDimArray[i][j];

        }

}

Definition

The nested for-loop requires two different variables (i, j)to represent ROWS and COLS respectively.



for (int i = 0; i < ROWS; i++)

{

        for (int  j= 0;  < COLS; j++)

        {

                  cin >>  twoDimArray[i][j];

        }

}

Term

Spot the error in the code:


string cities[3] = {'New York', 'Boston', 'Phoenix'};

Definition

Since the city names are strings, they require double quotations.




string cities[3] = {"New York", "Boston", "Phoenix"};

Term

Will the following code compile?

 

double numbers[] = {12.43, 2.1, .01, 13.44};

Definition

Yes.

 

Although there is no declared size inside the brackets [],   the compile assumes the size will be 4 because we've assigned it 4 double type identifiers.

Term

Identify the error:


double testScores[] = {74, 68, 85, 95, 90};

Definition
None.
Supporting users have an ad free experience!