C Functions Test 2


6) Which library function can change an unsigned long integer to a string?

  1. system()
  2. ltoa()
  3. ultoa()
  4. unsigned long can't be change into a string

The correct option is (c).

Explanation:

The function ultoa() is used for converting an unsigned long integer to a string.

7) What is the output of below C program?

  1. k=30
  2. k=31
  3. k=32
  4. k=33

The correct option is (d).

Explanation:

Step 1: int k=30; The variable k is declared as an integer type and initialized to 30.

Step 2: k=function1(k= function1(k=function1(k))); The function1 (k) increment the value of k by 1 and return it. In program function1(k) is called 3 times. Hence the value of k increments from k=30 to 33. Therefore result stored in the variable k=33.

Step 3: printf("k=%d\n", k); It prints the value of variable k =33.

8) What is the purpose of using fflush() function?

  1. Flushes only specified stream.
  2. Flushes file buffer.
  3. Flushes input/output buffer.
  4. Flushes all streams and specified buffer.

The correct option is (d).

Explanation:

Using "flush()" function we can flush any buffered output associated with a filename, which is either a shell command for redirecting output or a file opened for writing.

For example:

9) What is the value returned by strcmp() function when two strings are the equal?

  1. 2
  2. 1
  3. 0
  4. Error

The correct option is (c).

Explanation:

C library function strcmp() compares the two strings with each other and the value is return accordingly.

Comparison occurs between a first string (str1) with a second string (str2).

On comparing the two string, the values return by a function strcmp() are:

  • If, str1 is equal to str2 then Return value = 0
  • If, str1 is greater than str2 then Return value > 0
  • If, str1 is less than str2 then Return value < 0

10) Which function disconnects the stream from a file pointer?

  1. fclose()
  2. fremove()
  3. remove()
  4. file pointer set to NULL

The correct option is (a).

Explanation:

Function that disconnects the stream from a file pointer is fclose(), it flushes the buffers associated with a stream and disconnects the stream from a file pointer.





Latest Courses