This set of C Multiple Choice Questions & Answers (MCQs) focuses on “General Utilities – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What will be the output of the following C code?
char word[20 ] = "1.234555 WELCOME"; char *w; double dis; dis= strtod(word, &w); printf("The number is %lf\n", dis); printf("String is |%s|", w);
a) The number is 1.234555 String is |WELCOME|
b) The number is 1.2345550 String is |WELCOME|
c) The number is 1.234555 String is |1.234555 WELCOME|
d) Errror
View Answer
Explanation: strtod() function is used to return the converted floating point number as a double value, else zero value (0.0) is returned.
2. Which statement is correct work reference to endptr?
double strtod(const char *nptr, char **endptr);
a) A pointer to the starting string is stored in the object pointed to by endptr, provided that endptr is a null pointer
b) A pointer to the final string is stored in the object pointed to by endptr, provided that endptr is not a null pointer
c) A pointer to the final string is stored in the object pointed to by endptr, provided that endptr is a null pointer
d) A pointer to the starting string is stored in the object pointed to by endptr, provided that endptr is not a null pointer
View Answer
Explanation: If endptr is not NULL then endptr stores the pointer to a character after the last character.
3. Which of the following functions decomposes the input string into three pans: an initial, possibly empty, sequence of white-space characters?
a) strtod()
b) atof()
c) atol()
d) strtol()
View Answer
Explanation: The strtol() function is used to convert the initial portion of the string pointed to by, to long int representation. First, it decomposes the input string into three pans: an initial, empty, white-space characters (as specified by the isspace function).
4. The______function is used to convert the initial portion of the string pointed to by, to unsigned long int representation.
a) strtod()
b) atol()
c) strtoul()
d) strtol()
View Answer
Explanation: unsigned long int strtoul(const char *p, char **ptr, int base) function is used to convert the initial part of the string in p to an unsigned long int value according to the given base,it must be between 2 and 36 inclusive, or be the special value 0.
5. Which of the following is the correct syntax of the function strtoul()?
a) unsigned long int strtoul(const char *n, char **ptr, int base)
b) unsigned long int strtoul(const char *n, char **ptr)
c) unsigned long int strtoul(const char *n)
d) int strtoul(const char *n)
View Answer
Explanation: usigned long int strtoul(conmt char *n, char **ptr, int base); The strtoul() function is used to convert the initial portion of the string pointed to by n to unsigned long int representation.
6. Select the right statement with reference to malloc() and calloc().
a) malloc() does not set the memory to zero whereas calloc() sets allocated memory to zero
b) malloc() sets the memory to zero whereas calloc() does not set allocated memory to zero
c) malloc() sets the memory to zero whereas calloc() sets allocated memory to zero
d) malloc() does not set the memory to zero whereas calloc() does not set allocated memory to zero
View Answer
Explanation: The difference in malloc() and calloc() is that calloc() sets the memory to zero whereas malloc()does not sets allocated memory to zero.
7. The calloc() function allocates space for an array of n objects, each of whose size is defined by size. Space is initialized to all bits zero.
a) true
b) false
View Answer
Explanation: void *calloc(size-t n, size-t size);
This function is used to allocate the requested memory and returns a pointer to it.
8. Is this right explanation to the given code?
void *calloc(size_t n, size_t size) #n -- This is the number of elements to be allocated. #size -- This is the size of elements.
a) true
b) false
View Answer
Explanation: void *calloc(size_t n, size_t size) The calloc() function allocates space for an array of n objects, each of whose size is given by size. The space is initialized to all bits zero.
9. Which among the given function does not return a value?
a) strtoul()
b) strtol()
c) rand()
d) srand()
View Answer
Explanation: void srand(unsigned int seed);
The srand() function uses argument as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand(). The srand() function returns no value.
10. Which function returns a pseudo-random integer?
a) srand()
b) rand()
c) malloc()
d) alloc()
View Answer
Explanation: int rand (void) ;
The rand() function is used to compute a sequence of pseudo-random integers in the range 0 to RAND-MAX. The rand function returns a pseudo-random integer.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Watch Advanced C Programming Videos
- Apply for C Internship
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Check Computer Science Books