Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Which of the following correctly declares an array? A. int anarray[10]; B. in

ID: 3816812 • Letter: 1

Question

1. Which of the following correctly declares an array?


A. int anarray[10];
B. int anarray;
C. anarray{10};
D. array anarray[10];

2. What is the index number of the last element of an array with 29 elements?

A. 29
B. 28
C. 0
D. Programmer-defined

3. Which of the following is a two-dimensional array?

A. array anarray[20][20];
B. int anarray[20][20];
C. int array[20, 20];
D. char array[20];

4. Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements?

A. foo[6];
B. foo[7];
C. foo(7);
D. foo;

5. A pointer declared void can be dereferenced ? ( T/F)
//Talk about Prototypes. What is a string?

#include <stdio.h>

    void main()

    {

        int a[3] = {1, 2, 3};

        int *p = a;

        printf("%p %p", p, a);

    }

7.

#include <stdio.h>

void main()

{

char *s = "hello";

char *p = s;

printf("%p %p", p, s);

}

8.

9.

    int main()

    {

        const int ary[4] = {1, 2, 3, 4};

        int *p;

        p = ary + 3;

        *p = 5; //WONT COMPILE because const

        printf("%d ", ary[3]);

    }

10.

The elements in the array of the following code are:
int array[5]={5};

a) 5, 5, 5, 5, 5
b) 5, 0, 0, 0, 0
c) 5, (garbage), (garbage), (garbage), (garbage)
d) (garbage), (garbage), (garbage), (garbage), 5

11.

#include <stdio.h>

    int main()

    {

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

        int p[4];

        p = ary;

        printf("%d ", p[1]);

    }

12. If there is any error while opening a file, fopen will return
a) Nothing
b) EOF
c) NULL
d) Depends on compiler

13. Remember when the question is length of a string, you don’t need to count the null terminator (‘’). But is the question is how many characters are there in the string( or character array) you count null terminator (‘’)

This is not a question. It is an FYI.

14.

The value obtained in the function is given back to main by using ________   keyword?

15.

Identify the incorrect file opening mode from the following.

A - r

B - w

C - x

D - a

16.

Printf(“%d”,1+(rand()%11)); ------ ???

Next question – if rand() returns 123

17. x address 2016
    c address 3012

Integer type is 4 bytes long on this system.

Int x[8]={11,8,2,3,5,6,4,1};

int *c=x;

1.printf(“%d”,x[4]); //5

2.printf(“%d”,*(x+4)); //5

3.printf(“%d”,&x); //COMPILE ERROR BECAUSE EXPECTS AN INT

4.printf(“%p”,&x); //2016

5.printf(“%p”,&c); //3012

6.printf(“%p”,c); //2016

7.printf(“%d”,*(c+3)); //3

8.C++;

9.printf(“%p”,c); //2020

10.printf(“%d”,*c); //8

11. C+=4; //c=c+4

12.printf(“%d”,*(c+0)); same as *c and it is 6

13.printf(“%d”,*(c+1)); //4

14.printf(“%p”,c); // 2036

15.printf(“%d”,x);//compile error

Explanation / Answer

Answers:

1) Answer:A) int anarray[10];

      The above statement creates integer array of size 10. Therefore it is correct.

     Syntax for array declaration is,

    datatype arr_name[size];

2) Answer:B)29

   Array index starts from 0. Therefore 29th element has index number 28.

3) Answer:B) int anarray[20][20];

Above statement create two dimensional integer array anarray.

Syntax for declaring two dimensional array is,

datatype arr_name[rowsize][columnsize]. Therefore answer is B.

4)Answer:A) foo[6];

    Array undex start from 0. therefore foo[6]; acces 7th element.