Home » C Functions Test 1

C Functions Test 1


1) What is the built-in library function for comparing the two strings?

  1. strcmp()
  2. equals()
  3. str_compare()
  4. string_cmp()

The correct option is (a).

Explanation:

The strcmp() is a built-in function available in “string.h” header file. It is used for comparing the two strings. It returns 0 if both are same strings. It returns positive value greater than 0 if first string is greater than second string, otherwise it returns negative value.

2) What is passed when we pass an array as a function argument?

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

The correct option is (a).

Explanation:

On passing the name of array as function argument; the name contain the base address of an array and base address is updated inside a main function.

3) Which function finds the first occurrence of a substring in another string?

  1. strchr()
  2. strnset()
  3. strstr()
  4. None of these.

The correct option is (c).

Explanation:

The first occurrence of a substring in another string is founds in strstr() function.

4) What is the built-in library function for adjusting the allocated dynamic memory size.

  1. calloc
  2. malloc
  3. realloc
  4. resize

The correct option is (c).

Explanation:

realloc() is a built in library function for adjusting the dynamic memory size. malloc() and calloc() allocates the memory but don’t resize. There is no built in function with a name resize().

5) Which keyword is used to transfer control from a function back to the calling function?

  1. return
  2. go back
  3. switch
  4. goto

The correct option is (a).

Explanation:

In C language, the return function stops the execution of function and returns a value to calling function. Execution is begins in a calling function by instantly following the call.

You may also like