Javatpoint Logo
Javatpoint Logo

C Array Test 3


11) Which statements are correct about the program given below?

  1. The code is erroneous since the values of an array are getting scanned through the loop.
  2. The code is erroneous since the statement declaring an array is invalid.
  3. The code is erroneous since the subscript for an array used in for loop is in the range 1 to size.
  4. The code is correct and runs successfully.

The correct option is (b).

Explanation:

In program the statement int arr[size]; produces an error, because we cannot initialize the size of array dynamically. Constant expression is required for initialize the size of array. For Example: int arr[20];

Therefore the code is erroneous since the statement declaring an array is invalid.

12) Are the expression &arr and arr different for an array of 15 integers?

  1. Yes
  2. No

The correct option is (a).

Explanation:

Yes, both mean two different things. 'arr' gives the address of first int, whereas the '&arr' gives the address of array of ints.

Therefore the expression '&arr' and 'arr' are different for an array of 15 integers.

13) Is there any difference in the below declarations?

  1. Yes
  2. No

The correct option is (b).

Explanation:

No, both the declarations are same. It is a prototype for function fun() that accepts one integer array as parameter and an integer value is return.

14) What will be the output of the below program?

  1. 2
  2. 0
  3. 20
  4. 16

The correct option is (c).

Explanation:

Step 1: int arr[2]={20}; The variable arr[2] is declared as an integer array with size of '3' and it's first element is initialized with value '20'(means arr[0]=20)

Step 2: printf("%d\n", 0[arr]); It prints the first element value of variable 'arr'.

Therefore the output of the program is 20.

15) What will be the output of the program if an array begins with address 65486?

  1. 65486, 65486
  2. 65486, 65490
  3. 65486, 65487
  4. 65486, 65488

The correct option is (a).

Explanation:

Step 1: int arr[] = {10, 11, 12, 15, 23}; The variable 'arr' is declared as an integer array and initialized.

Step 2: printf("%u, %u\n", arr, &arr); Here, the base address of the array is 65486.

Hence the arr, &arr is pointing towards the base address of the array arr.

Hence the output of the program is 65486, 65486






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA