REVIEW OF THE BASIC ENTRY-LEVEL KNOWLEDGE

Home |

 

 

  • In the 121 zone, questions are in bold throughout
  • with unbolded answers immediately below
  • Questions marks and italics mean I wasn't sure
  • Please email me if you can help... thanks

When writing prototype declarations, is the data type necessary?

And is the variable name necessary?

 

 

Yes.

No, all we need is the type.

 

 

Check this for possible errors: 

 

void greeting(void);

int main(void)

{    greeting();    return 0; }

 

void greeting(void)

{   cout<<"Hello world";    return; }

 

 

It needs #include

 

 

Pass By ------- sends the actual variable into the called function, not a copy.

 

 

Reference. So the variable is changed by the function.

 

 

Is this code fragment okay?

What will it return?

 

int getNumber()

{   int x, y; cin >> x >> y; return(x,y); }

 

 

Nope! Don’t try to return more than one value from a function.

 

y will return here because of the comma operator.

 

 

Arrays can be referenced in 2 ways, which are -----

 

 

Subscript form, eg num19.

Index form, eg num[19]

 

 

Array initialisation: Give examples of ---

 

Basic initialisation.

Initialisation without size.

Partial initialisation.

Initialisation to all zeros.

 

 

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

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

int num[5] = {1,2}; // the rest are filled with zeros

int num[5] = n{0};

 

 

What does this do?

 

for(int i=0; ip>

   print_square(base[i]);

 

 

It passes the data from an array into a function, element by element.

 

 

What does this do?

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

…

ave = average(base);

 

 

It passes the whole array called base into the function called average.

 

 

3dimensional arrays:

 

What do a, b, c represent in array[a][b][c]?

 

 

a= planes, they always come first in any list of 3 dimensions.

b=rows,

c=columns.

 

 

Accessing a struct element – what will this print?

 

struct SAMPLE

{ int x, y; float f; char c;};

SAMPLE sam1 = {2, 5, 3.2, 'A'};

cout << sam1.y;

 

How to copy the whole of the array sam1 to sam2?

 

 

5.

 

Copying the array is simple! Use Assignment (=), ie:

sam2 = sam1

 

 

T/F? There's no way to pass by value in an array.

T/F? Do not declare/use an array with a non-constant size.

 

 

T.

T. We need to reserve a defined number of elements at the start, so it needs a constant. (Later we cover pointers and dynamic arrays.)

 

 

Class is an extension of what data type?

 

 

Struct.

 

 

With loops and conditional statements (such as if), we enter the conditional statements if the test-condition is (true / false).

 

 

T. (F bypasses the loop.)

 

 

T/F?

A condition is true if it's not equal to 0.

A condition is true if it =1.

A condition is false if it is =0.

 

 

T.

T. A condition is true if it is "not equal to zero".

T.

 

 

Struct: What's the format of a struct declaration?

 

 

struct typeName { field list };

 

Example:

struct typeName

{

   type1 fieldName1;

   type2 fieldName2;

   ……

   typen fieldNamen;

}; // don’t forget the semicolon

 

 

Strings (= arrays of characters) are manipulated by string.h functions that begin with ----- 

Show us how much you know – give us some examples.

 

 

str.

Examples: strcmp( ), strcpy( ), strstr( ).

 

 

"There is only only C++ loop which is --------;

all the others are simply variations of this one."

 

Agree? – If so, which loop?

 

 

Hope you agree. Its pattern is:

 

while (condition) statement;

 

 

"Enter" can be coded as -----

 

 

\n

 

 

Convert this for loop into a while loop:

 

for(initialisation; condition; post) statement;

 

 

initialisation;

while (condition)

{
statement;
post;
}

 

 

Why is the ampersand here? –

 

for(int i=0; ip>

   cout << &data[i] << " " << endl;

 

If the string contained "Good", what would be the printed output?

 

 

So you can use the string but not necessarily have to start at the beginning.

 

This would print:

 

Good

ood

od

d

 

setstats 1