Sail E0 Webinar

MCQs

Total Questions : 27 | Page 3 of 3 pages
Question 21.

Does there any function exist to convert the int or float to a string?


  1.    Yes
  2.    No
 Discuss Question
Answer: Option A. -> Yes


1. itoa() converts an integer to a string.
2. ltoa() converts a long to a string.
3. ultoa() converts an unsigned long to a string.
4. sprintf() sends formatted output to a string, so it can be used to convert any type of values to string type.
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int num1 = 12345;
float num2 = 5.12;
char str1[20];
char str2[20];
itoa(num1, str1, 10); /* 10 radix value */
printf("integer = %d string = %s n", num1, str1);
sprintf(str2, "%f", num2);
printf("float = %f string = %s", num2, str2);
return 0;
}
// Output:
// integer = 12345 string = 12345
// float = 5.120000 string = 5.120000


Question 22.

What is stderr ?


  1.    standard error
  2.    standard error types
  3.    standard error streams
  4.    standard error definitions
 Discuss Question
Answer: Option C. -> standard error streams

The standard error(stderr) stream is the default destination for error messages and other 

diagnostic warnings. Like stdout, it is usually also directed to the output device of the 

standard console (generally, the screen).


Question 23.

Which standard library function will you use to find the last occurance of a character in a string in C?


  1.    strnchar()
  2.    strchar()
  3.    strrchar()
  4.    strrchr()
 Discuss Question
Answer: Option D. -> strrchr()


strrchr() returns a pointer to the last occurrence of character in a string.
Example:


#include<stdio.h>
#include<string.h>
int main()
{
char str[30] = "12345678910111213";
printf("The last position of '2' is %d.\n",
strrchr(str, '2') - str);
return 0;
}


Output: The last position of '2' is 14.


Question 24.

Input/output function prototypes and macros are defined in which header file?


  1.    conio.h
  2.    stdlib.h
  3.    stdio.h
  4.    dos.h
 Discuss Question
Answer: Option C. -> stdio.h

stdio.h, which stands for "standard input/output header", is the header in the C standard library 
Question 25.

What will the function rewind() do?


  1.    Reposition the file pointer to a character reverse.
  2.    Reposition the file pointer stream to end of file.
  3.    Reposition the file pointer to begining of that line.
  4.    Reposition the file pointer to begining of file.
 Discuss Question
Answer: Option D. -> Reposition the file pointer to begining of file.

rewind() takes the file pointer to the beginning of the file. so that the next I/O operation

 will take place at the beginning of the file.
Example: rewind(FilePointer);


Question 26.


Which standard library function will you use to find the last occurance of a character in a string in C?



  1.    strnchar()
  2.    strchar()
  3.    strrchar()
  4.    strrchr()
 Discuss Question
Answer: Option D. -> strrchr()

strrchr() returns a pointer to the last occurrence of character in a string.


#include <stdio.h>
#include <string.h>
int main()
{
char str[30] = "12345678910111213";
printf("The last position of '2' is %d.n",
strrchr(str, '2') - str);
return 0;
}
Output: The last position of '2' is 14.


Question 27.

What is the purpose of fflush() function.


  1.    flushes all streams and specified streams.
  2.    flushes only specified stream.
  3.    flushes input/output buffer.
  4.    flushes file buffer.
 Discuss Question
Answer: Option A. -> flushes all streams and specified streams.

"fflush()" flush any buffered output associated with filename, which
is either a file opened for writing or a shell command for redirecting
output to a pipe or coprocess.

Example:
fflush(FilePointer);
fflush(NULL); flushes all streams.



Latest Videos

Latest Test Papers