Which of the following is used to dynamically allocate memory in C?
Anew()
Balloc()
Cmalloc()
Dcreate()
Correct Answer:
C. malloc()
Explanation:
malloc() (memory allocation) is the standard function in C for dynamic memory allocation. It returns a void pointer to the allocated memory. The syntax is: ptr = (type*)malloc(size);
Which function is used to compare two strings in C?
Astrcmp()
Bstrcomp()
Ccompare()
Dstrcmpare()
Correct Answer:
A. strcmp()
Explanation:
strcmp() is the standard library function used to compare two strings. It returns 0 if strings are equal, negative if first string is less, and positive if first string is greater. It's declared in string.h.
Which loop in C does NOT check the condition before executing the loop body?
Afor loop
Bwhile loop
Cdo-while loop
Dforeach loop
Correct Answer:
C. do-while loop
Explanation:
The do-while loop executes the loop body at least once before checking the condition. Other loops check the condition before execution. Syntax: do { } while(condition);