An array is:
- a group of values having a common variable name and all of the same data
type.
- a collection of elements of different data types that are stored in
adjacent memory locations.
- a variable that contains multiple values of different data types.
- a location in memory that holds multiple values of the same data type.
How is an individual element in an array addressed?
The subscript identifies the ________________ of a particular element in
the array?
What does the following code fragment do?
sum = 0;
for(row=0; row<n_rows; row++)
sum +=
Table[row][2];
Give corresponding snapshots of memory after the following code fragment
is executed. Use "?" to indicate an array element that is not initialized.
int r,c,x[4][5]
...
for(r=0; r<=3; r++)
{
for(c=0;c<=4;
c++)
{
x[r][c] = r + c;
}
}
Give the value in sum after the following code fragment is
executed:
int x[4][4] =
{{1,2,3,4},{5,6,7,8},{9,8,7,3},{2,1,7,1}};
...
sum = 0;
for(i=1; i<=3; i++)
{
for(j=0;
j<=3; j++)
{
if(x[i][j] > x[i-1][j])
sum++;
}
}
What does strcmp(s[],t[]) return if:
char s[] = "Hello";
char t[7] = "HELLO";
What is the result of the following code fragment?
int x[][3] = {{2,3,1}, {0,-3,5}};
...
return (x[2][2]);
What is the value of y[2][3] after the following code fragment has been
run?
int i,j, n=3;
double y[n][n];
...
for(i=0; i<=n-1; i++)
{
for(j=0;
j<=n-1; j++)
{
y[j][i] = n*(j+i);
}
}
What is the average and the median of x if:
x[9] = {0,1,2,2,6,6,6,7,8};
How is standard deviation related to variance?
What is variance a measure of?
In the function call:
double mean( double x[], int n)
What value should n contain?
Arrays are passed into functions by reference rather than by value. What
does that mean?
A pointer variable
- contains the data stored at a location in memory.
- contains the address of a memory location.
- can be used in input statements, but not output statements.
- can be changed to different values in both input and output statements.
How would you assign to the variable name the value of a variable
referenced by the pointer a?
- a = &name;
- name = &a;
- a = *name;
- name = *a;
What is the advantage of using pointers in functions?
What are the potential problems if a pointer is not initialized before
use? If a pointer is originally unused what should the pointer be initialized
to?
A function prototype is given as: