C Functions 2

  • ltoa
  • ultoa
  • unsigned long can't be change into a string

Explanation:

The ultoa function is utilized to convert an unsigned long integer into a string.

7) What is the output of below C program?

Example

#include<stdio.h>
int function1(int);

int main()
{
    int k=30;
    k = function1(k=function1(k=function1(k)));
    printf("k=%d\n", k);
    return 0;
}
int function1(int k)
{
    k++;
    return k;
}
  • k=30
  • k=31
  • k=32
  • k=33

Explanation:

Initializing the variable k to 30, it is declared as an integer data type.

Step 2: In this step, the variable k is manipulated using the function1 as follows: k = function1(k = function1(k = function1(k))). The function1(k) increments the value of k by 1 each time it is called. As the function1(k) is invoked 3 times in the program, the initial value of k, which is 30, is incremented thrice to reach 33. Therefore, the final result is stored in the variable k as 33.

Step 3: Utilizing the printf function, the value of the variable k is displayed as 33 by using the format specifier %d within the string "k=%d\n".

8) What is the purpose of using fflush function?

  • Flushes only specified stream.
  • Flushes file buffer.
  • Flushes input/output buffer.
  • Flushes all streams and specified buffer.

Explanation:

By utilizing the "flush" function, we can clear any stored output linked to a specified filename, whether it serves as a command in the shell to redirect output or as a file that has been opened for the purpose of writing data.

For example:

Example

fflush (FilePointer);
 fflush (NULL); //It flushes all streams

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

  • Error

Explanation:

The C library function strcmp is responsible for comparing two strings and returning a value based on their comparison.

Example

int strcmp (const char *str1, const char *str2)

A comparison is made between an initial string (str1) and a subsequent 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?

  • fclose
  • fremove
  • remove
  • file pointer set to NULL

Explanation:

The function responsible for disconnecting the stream from a file pointer is fclose; it clears the buffers linked to a stream and severs the connection between the stream and a file pointer.

Input Required

This code uses input(). Please provide values below: