CIS3355: Data Structures

The University of Texas at El Paso

Professor Kirs

 

Arrays: Sample Problems and Exercises

 

1.0100   What is the main advantage of an array?

 

      SEE SOLUTION

 

1.0110  What is the main disadvantage of an array?

 

      SEE SOLUTION

 

50.0100  What are the major differences between automatic, static, and external arrays?

 

      SEE SOLUTION

 

100.0010 Given:  char mystring[30];

 

If the base address of mystring is 12453, what would the following command produce?

 

Printf(“%lu”, &mystring[24]);

 

      SEE SOLUTION

 

100.0014 Given:  short shortinteger[100];

 

If the base address of shortinteger is 75282, what would the following command produce?

 

Printf(“%lu”, &shortinteger [200]);

 

      SEE SOLUTION

 

100.0016 Given:  int reginteger[50];

 

If the base address of reginteger is 16552, what would the following command produce?

 

Printf(“%lu”, &reginteger [15]);

 

      SEE SOLUTION

 

100.0018 Given:  long longinteger[50];

 

If the base address of longinteger is 13454, what would the following command produce?

 

Printf(“%lu”, & longinteger[22]);

 

      SEE SOLUTION

 

100.0020 Given:  float realnumber[50];

 

If the base address of realnumber is 21457, what would the following command produce?

 

Printf(“%lu”, &realnumber[34]);

 

      SEE SOLUTION

 

100.0022 Given:  double doublenumber[50];

 

If the base address of doublenumber is 15642, what would the following command produce?

 

Printf(“%lu”, & doublenumber[19]);

 

      SEE SOLUTION

 

100.0024 Given:  long double longdoublenumber[50];

 

If the base address of longdoublenumber is 43768, what would the following command produce?

 

Printf(“%lu”, & longdoublenumber [187]);

 

      SEE SOLUTION

 

100.0030 Given char  mychar[8][7];

 

If the base address of the array is 7200, at what address will we find mychar[5][3] ?

 

      SEE SOLUTION

 

100.0032 Given:  unsigned long  mydata[4][6];

 

If the base address of the array is 7200, at what address will we find mydata[3][2] ?

 

      SEE SOLUTION

 

100.0034 Given:  float mydata[20][10];

 

If the base address of the array is 7200, at what address will we find mydata[12][7] ?

 

      SEE SOLUTION

 

100.0036 Given:  double mydata[32][15];

 

If the base address of the array is 7200, at what address will we find mydata[73][9] ?

 

      SEE SOLUTION

 

100.0090 When I entered the C code:

 

long myarray[5];

printf(“%lu”, &myarray[3]);

 

      I received the output:   56884

      Looking at RAM, I found:

 

56868

56869

56870

56871

00001100

00000001

00000000

00000001

56872

56873

56874

56875

00010011

00000100

00000000

00001000

56876

56877

56878

56879

00000000

00001001

00000000

00000001

56880

56881

56882

56883

00001001

00010000

00000001

001100010

56884

56885

56886

56887

00000001

11000101

11011011

111010100

56888

56889

56890

56891

11111111

11111111

11111111

11101010

56892

56893

56894

56895

00101101

00011001

00000010

01110001

 

A.   What would be the output of the statement:   printf(“%lu”, &myarray[1]); ?

 

      SEE SOLUTION

 

B.   What would be the output of the statement:   printf(“%d”, myarray[4]); ?

 

      SEE SOLUTION

 

C.   Explain why I can enter the command:  printf(“%d”, myarray[76]);  and still receive output, even though I declared myarray to only have 5 elements.

 

      SEE SOLUTION

 

100.0100 When I entered the c code:

 

int myarray[7], *mypointer;

mypointer = &myarray[3];

printf(“%lu %lu”,myarray, mypointer);

 

      I received the output:   56871  56889

      Looking at RAM, I found:

 

56868

56869

56870

56871

00001100

00000001

00000000

00000001

56872

56873

56874

56875

00010011

00000100

00000000

00001000

56876

56877

56878

56879

00000000

00001001

00000000

00000001

56880

56881

56882

56883

00001001

00010000

00000001

00000000

56884

56885

56886

56887

11010111

00001010

01110101

11111100

56888

56889

56890

56891

11010110

00000000

00000000

11011110

56892

56893

56894

56895

00101101

00011001

00000010

01110001

 

a.   What would be the output of the statement:   printf(“%lu”, &myarray[2]); ?

 

      SEE SOLUTION

 

b.   What would be the output of the statement:   printf(“%d”, myarray[7]); ?

 

      SEE SOLUTION

 

c.   What would be the output of the statement:   printf(“%d”, *mypointer); ?

 

      SEE SOLUTION

 

d.   What would be the output of the statement:   printf(“%lu”, --mypointer); ?

 

      SEE SOLUTION

 

e.       Disregarding the previous question, What would be the output of the statement:

      printf(“%d”, *mypointer);  AFTER we issue the statement:    ++mypointer; ?

 

      SEE SOLUTION