C Questions and Answers – General Utilities – 2

«
»

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.

advertisement

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

Answer: a
Explanation: strtod() function is used to return the converted floating point number as a double value, else zero value (0.0) is returned.
advertisement
advertisement

2. Which statement is correct work reference to endptr?

advertisement
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

Answer: b
Explanation: If endptr is not NULL then endptr stores the pointer to a character after the last character.
advertisement

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

Answer: d
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

Answer: c
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.
advertisement

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

Answer: a
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

Answer: a
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

Answer: a
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

Answer: a
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

Answer: d
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

Answer: b
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.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.