Sail E0 Webinar

MCQs

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

scanf() or atoi() function can be used to convert a string like "436" in to integer.


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

scanf is a function that reads data with specified format from a given string stream source. 
scanf("%d",&number);

atoi() convert string to integer. 
var number;
number = atoi("string");



Question 2.

The prototypes of all standard library string functions are declared in the file string.h.


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

string.h is the header in the C standard library for the C programming language which contains 

macro definitions, constants, and declarations of functions and types used not only for string 

handling but also various memory handling functions.


Question 3.

The itoa function can convert an integer in decimal, octal or hexadecimal form to a string.


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


itoa() takes the integer input value input and converts it to a number in base radix. The resulting number a sequence of base-radix digits.
Example:


/* itoa() example */
#include<stdio.h>
#include <stdlib.h>
int main ()
{
int no;
char buff [50];
printf ("Enter number: ");
scanf ("%d",&no);
itoa (no,buff,10);
printf ("Decimal: %s\n",buff);
itoa (no,buff,2);
printf ("Binary: %s\n",buff);
itoa (no,buff,16);
printf ("Hexadecimal: %s\n",buff);
return 0;
}
Output:
Enter a number: 1250
Decimal: 1250
Binary: 10011100010
Hexadecimal: 4e2


Question 4.

Is standard library a part of C language?


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

The C standard library consists of a set of sections of the ISO C standard which describe 

a collection of header files and library routines used to implement common operations, 

such as input/output and string handling, in the C programming language. The C standard 

library is an interface standard described by a document; it is not an actual library of software 

routines available for linkage to C programs.


Question 5.

If the two strings are found to be unequal then strcmp returns difference between the first

 non-matching pair of characters.


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True


g = strcmp(s1, s2); returns 0 when the strings are equal, a negative integer when s1 is less than s2, or a positive integer if s1 is greater than s2, that strcmp() not only returns -1, 0 and +1, but also other negative or positive values(returns difference between the first non-matching pair of characters between s1 and s2).
A possible implementation for strcmp() in "The Standard C Library".


int strcmp (const char * s1, const char * s2)
{
for(; *s1 == *s2; ++s1, ++s2)
{
if(*s1 == 0)
return 0;
}
return *(unsigned char *)s1 < *(unsigned char *)s2 ? -1 : 1;
}


Question 6.

Data written into a file using fwrite() can be read back using fscanf()


  1.    True
  2.    False
 Discuss Question
Answer: Option B. -> False

fwrite() - Unformatted write in to a file.
fscanf() - Formatted read from a file.


Question 7.

ftell() returns the current position of the pointer in a file stream.


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True


The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream.
Example:


#include<stdio.h>
int main(void)
{
FILE *stream;
stream = fopen("MYFILE.TXT", "w+");
fprintf(stream, "This is a test");
printf("The file pointer is at byte %ld\n", ftell(stream));
fclose(stream);
return 0;
}


Question 8.

FILE is a structure suitably typedef'd in "stdio.h".


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True

FILE - a structure containing the information about a file or text stream needed to perform 

input or output operations on it, including:
=> a file descriptor, the current stream position,
=> an end-of-file indicator, 
=> an error indicator, 
=> a pointer to the stream's buffer, if applicable

fpos_t - a non-array type capable of uniquely identifying the position of every byte in a file.
size_t - an unsigned integer type which is the type of the result of the sizeof operator.


Question 9.


What will be the output of the program?


#include<stdio.h>
int main()
{
int i;
char c;
for(i=1; i
  1.    aaaa
  2.    aaaaa
  3.    Garbage value.
  4.    Error in ungetc statement.
 Discuss Question
Answer: Option B. -> aaaaa

for(i=1; i<=5; i++) Here the for loop runs 5 times.

Loop 1
scanf("%c", &c); Here we give 'a' as input. 
printf("%c", c); prints the character 'a' which is given in the previous "scanf()" statement. 
ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.

Loop 2
Here the scanf("%c", &c); get the input from "stdin" because of "ungetc" function. 
printf("%c", c); Now variable c = 'a'. So it prints the character 'a'. 
ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.

This above process will be repeated in Loop 3Loop 4Loop 5.


Question 10.

It is necessary that for the string functions to work safely the strings must be terminated with ''.


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True

C string is a character sequence stored as a one-dimensional character array and 

terminated with a null character('', called NULL in ASCII). 
The length of a C string is found by searching for the (first) NULL byte.


Latest Videos

Latest Test Papers