Javatpoint Logo
Javatpoint Logo

C Array Test 1


1) In C, if we pass an array as an argument to a function, what actually get passed?

  1. Address of the last element of array
  2. Base address of the array
  3. Value of elements in array
  4. First element of the array

The correct option is (b).

Explanation:

In C language when we pass an array as a function argument, then the Base address of the array will be passed.

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

  1. Strings are Equal
  2. No output
  3. Runtime error
  4. Compilation error

The correct option is (a).

Explanation:

In the program we are comparing the base address of 'x' and 'y' and they are not same.

Therefore the program has No output.

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

  1. 5 9
  2. 9 20
  3. 2 9
  4. 2 5

The correct option is (c).

Explanation:

The strlen(x) function is used for finding the length of string 'x'. In program the length of string is count of character upto '\0'. Hence the string length output is 2.

The sizeof(x) function is used for finding the size of string 'x'. In program sizeof() returns the size of the complete array. Hence the size of array output is 9.

Therefore the combined output of the program is 2 9.

4) A pointer to a block of memory is effectively same as an array.

  1. True
  2. False

The correct option is (a).

Explanation:

Using the standard library function malloc() and treat it as an array. The value of array is same as pointer to a block of memory.

Therefore it is possible to allocate block of memory at run time in array.

5) Which of the following statements are correct about array in C?

  1. The expression num[2] represents the very second element in the array
  2. The declaration of num[SIZE] is allowed if SIZE is a macro
  3. The array of int num[20]; can store 20 elements
  4. It is necessary to initialize array at the time of declaration
  1. 2
  2. 2,3
  3. 1,4
  4. 2,4

The correct option is (b).

Explanation:

  1. The expression num[2] represents the second element in array. This statement is false, because it represents the third element of the array.
  2. The declaration of num[SIZE] is allowed if SIZE is a macro. This statement is true, because MACRO is used for replacing the symbol size with given value.
  3. The array of int num[20]; can store 20 elements. This statement is true
  4. It is necessary to initialize array at the time of declaration. This statement is false
  5. Therefore statements '2' and '3' are correct.






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