Correct Answer: For input and output operations
Explanation: The <stdio.h> header file in C provides functions like printf() and scanf() for input and output operations.
Correct Answer: <stdlib.h>
Explanation: The <stdlib.h> header file in C provides functions like malloc() and free() for dynamic memory allocation and deallocation.
Correct Answer: #include <string.h>
Explanation: The strcmp() function in C is used for string comparison and is declared in the #include <string.h> header file.
Correct Answer: #include <math.h>
Explanation: The #include <math.h> header file in C provides declarations for mathematical functions like sqrt() and pow().
Correct Answer: For character handling functions
Explanation: The <ctype.h> header file in C provides functions like isdigit() and isalpha() for character classification and conversion.
Correct Answer: <time.h>
Explanation: The <time.h> header file in C provides functions for date and time manipulation, such as time(), localtime(), and strftime().
Correct Answer: #include <assert.h>
Explanation: The assert() macro in C is used for debugging purposes and is declared in the #include <assert.h> header file.
Correct Answer: #include <signal.h>
Explanation: The #include <signal.h> header file in C provides functions for handling signals, such as signal() and raise().
Correct Answer: #include <complex.h>
Explanation: The #include <complex.h> header file in C provides support for complex number arithmetic with functions like cabs() and carg().
Correct Answer: #include <pthread.h>
Explanation: The #include <pthread.h> header file in C provides support for creating and managing threads with functions like pthread_create() and pthread_join().
Correct Answer: sqrt()
Explanation: The sqrt() function in #include <math.h> calculates the square root of a number in C.
Correct Answer: pow()
Explanation: The pow() function in #include <math.h> computes the power of a number with specified base and exponent values.
Correct Answer: floor()
Explanation: The floor() function in #include <math.h> returns the largest integer value less than or equal to the given number.
Correct Answer: log()
Explanation: The log() function in #include <math.h> computes the natural logarithm (base e) of a number.
Correct Answer: fabs()
Explanation: The fabs() function in #include <math.h> computes the absolute value of a floating-point number.
Correct Answer: cos()
Explanation: The cos() function in #include <math.h> calculates the cosine of an angle in radians.
Correct Answer: ceil()
Explanation: The ceil() function in #include <math.h> returns the smallest integer value greater than or equal to the given number.
Correct Answer: fmod()
Explanation: The fmod() function in #include <math.h> computes the floating-point remainder of dividing one number by another.
Correct Answer: sinh()
Explanation: The sinh() function in #include <math.h> computes the hyperbolic sine of a number.
Correct Answer: hypot()
Explanation: The hypot() function in #include <math.h> calculates the square root of the sum of squares of its arguments.
#include <stdio.h>
#include <math.h>
int main() {
double x = 3.5;
double result = floor(x);
printf("Result: %.1f\n", result);
return 0;
}
Correct Answer: Computes the floor value of 3.5
Explanation: The floor() function in #include <math.h> returns the largest integer less than or equal to the given number. In this case, it computes and prints the floor value of 3.5, which is 3.
#include <stdio.h>
#include <math.h>
int main() {
double y = 4.2;
double z = -3.8;
double result = fmod(y, z);
printf("Result: %.2f\n", result);
return 0;
}
Correct Answer: Result: 1.40
Explanation: The fmod() function in #include <math.h> computes the remainder when y is divided by z. In this case, it calculates the remainder of 4.2 divided by -3.8, which is 1.40.
#include <stdio.h>
#include <math.h>
int main() {
double base = 2.0;
double exponent = 3.0;
double result = pow(base, exponent);
printf("Result: %.1f\n", result);
return 0;
}
Correct Answer: Computes the power of 2.0 raised to 3.0
Explanation: The pow() function in #include <math.h> calculates the power of a base raised to an exponent. Here, it computes 2.0 raised to the power of 3.0, resulting in 8.0.
#include <stdio.h>
#include <math.h>
int main() {
double angle = 1.5;
double result = cos(angle);
printf("Result: %.2f\n", result);
return 0;
}
Correct Answer: Computes the cosine of 1.5 radians
Explanation: The cos() function in #include <math.h> calculates the cosine of an angle in radians. Here, it computes the cosine of 1.5 radians and prints the result.
#include <stdio.h>
#include <math.h>
int main() {
double num = -8.5;
double result = fabs(num);
printf("Result: %.1f\n", result);
return 0;
}
Correct Answer: Result: 8.5
Explanation: The fabs() function in #include <math.h> computes the absolute value of a floating-point number. In this case, it calculates the absolute value of -8.5, resulting in 8.5.
#include <stdio.h>
#include <math.h>
int main() {
double x = 7.0;
double y = 24.0;
double result = hypot(x, y);
printf("Result: %.2f\n", result);
return 0;
}
Correct Answer: Computes the hypotenuse of a right triangle with sides 7.0 and 24.0
Explanation: The hypot() function in #include <math.h> computes the length of the hypotenuse of a right triangle with legs of lengths x and y. In this case, it calculates the hypotenuse of a triangle with sides 7.0 and 24.0, resulting in approximately 25.00.
#include <stdio.h>
#include <math.h>
int main() {
double num = 0.75;
double result = asin(num);
printf("Result: %.2f\n", result);
return 0;
}
Correct Answer: Computes the inverse sine (arcsine) of 0.75
Explanation: The asin() function in #include <math.h> computes the inverse sine (arcsine) of a number, which is the angle whose sine is num. In this case, it computes the arcsine of 0.75, resulting in approximately 0.85 radians.
#include <stdio.h>
#include <math.h>
int main() {
double num = 5.0;
double result = sqrt(num);
printf("Result: %.1f\n", result);
return 0;
}
Correct Answer: Result: 2.2
Explanation: The sqrt() function in #include <math.h> calculates the square root of a number. Here, it computes the square root of 5.0, resulting in approximately 2.2.
#include <stdio.h>
#include <math.h>
int main() {
double angle = 0.8;
double result = tan(angle);
printf("Result: %.2f\n", result);
return 0;
}
Correct Answer: Computes the tangent of 0.8 radians
Explanation: The tan() function in #include <math.h> calculates the tangent of an angle in radians. Here, it computes the tangent of 0.8 radians and prints the result.
#include <stdio.h>
#include <math.h>
int main() {
double num = 3.7;
double result = ceil(num);
printf("Result: %.1f\n", result);
return 0;
}
Correct Answer: Result: 4.0
Explanation: The ceil() function in #include <math.h> returns the smallest integer greater than or equal to the given number. In this case, it computes the ceiling of 3.7, resulting in 4.0.
Correct Answer: isalpha()
Explanation: The isalpha() function in <ctype.h> checks if a character is an alphabetic character (a-z or A-Z).
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '7';
if (isdigit(ch)) {
printf("%c is a digit.\n", ch);
} else {
printf("%c is not a digit.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘7’ is a digit
Explanation: The isdigit() function in <ctype.h> checks if a character is a digit (0-9). In this case, it checks if ‘7’ is a digit and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = 'A';
char lower = tolower(ch);
printf("Original character: %c, Converted to lowercase: %c\n", ch, lower);
return 0;
}
Correct Answer: Converts ‘A’ to lowercase
Explanation: The tolower() function in <ctype.h> converts an uppercase character to its corresponding lowercase character. Here, it converts ‘A’ to ‘a’ and prints both characters.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = 'x';
int result = isalnum(ch);
if (result) {
printf("%c is alphanumeric.\n", ch);
} else {
printf("%c is not alphanumeric.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘x’ is an alphanumeric character
Explanation: The isalnum() function in <ctype.h> checks if a character is alphanumeric (a-z, A-Z, or 0-9). In this case, it checks if ‘x’ is alphanumeric and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '$';
if (ispunct(ch)) {
printf("%c is a punctuation character.\n", ch);
} else {
printf("%c is not a punctuation character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘$’ is a punctuation character
Explanation: The ispunct() function in <ctype.h> checks if a character is a punctuation character (!”#$%&'()*+,-./:;<=>?@[\]^_`{|}~). In this case, it checks if ‘$’ is a punctuation character and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = ' ';
if (isspace(ch)) {
printf("%c is a whitespace character.\n", ch);
} else {
printf("%c is not a whitespace character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘ ‘ is a whitespace character
Explanation: The isspace() function in <ctype.h> checks if a character is a whitespace character (space, tab, newline, etc.). In this case, it checks if ‘ ‘ (space) is a whitespace character and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '!';
if (isprint(ch)) {
printf("%c is a printable character.\n", ch);
} else {
printf("%c is not a printable character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘!’ is a printable character
Explanation: The isprint() function in <ctype.h> checks if a character is printable (including alphanumeric characters and most punctuation). In this case, it checks if ‘!’ is printable and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '3';
int result = isxdigit(ch);
if (result) {
printf("%c is a hexadecimal digit.\n", ch);
} else {
printf("%c is not a hexadecimal digit.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘3’ is a hexadecimal digit
Explanation: The isxdigit() function in <ctype.h> checks if a character is a hexadecimal digit (0-9, a-f, A-F). In this case, it checks if ‘3’ is a hexadecimal digit and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = 'a';
char upper = toupper(ch);
printf("Original character: %c, Converted to uppercase: %c\n", ch, upper);
return 0;
}
Correct Answer: Converts ‘a’ to uppercase
Explanation: The toupper() function in <ctype.h> converts a lowercase alphabetic character to its corresponding uppercase character. Here, it converts ‘a’ to ‘A’ and prints both characters.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '\t';
if (iscntrl(ch)) {
printf("%c is a control character.\n", ch);
} else {
printf("%c is not a control character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘\t’ is a control character
Explanation: The iscntrl() function in <ctype.h> checks if a character is a control character (non-printable character, such as tab or newline). In this case, it checks if ‘\t’ (tab) is a control character and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '5';
if (isgraph(ch)) {
printf("%c is a graphical character.\n", ch);
} else {
printf("%c is not a graphical character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘5’ is a graphical character
Explanation: The isgraph() function in <ctype.h> checks if a character is a graphical character (printable and not a space). In this case, it checks if ‘5’ is a graphical character and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = ' ';
if (isblank(ch)) {
printf("%c is a blank character.\n", ch);
} else {
printf("%c is not a blank character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘ ‘ is a blank character
Explanation: The isblank() function in <ctype.h> checks if a character is a blank character (space or tab). In this case, it checks if ‘ ‘ (space) is a blank character and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = 'Q';
if (isupper(ch)) {
printf("%c is an uppercase letter.\n", ch);
} else {
printf("%c is not an uppercase letter.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘Q’ is an uppercase letter
Explanation: The isupper() function in <ctype.h> checks if a character is an uppercase letter (A-Z). In this case, it checks if ‘Q’ is an uppercase letter and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '!';
if (islower(ch)) {
printf("%c is a lowercase letter.\n", ch);
} else {
printf("%c is not a lowercase letter.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘!’ is a punctuation character
Explanation: The islower() function in <ctype.h> checks if a character is a lowercase letter (a-z). In this case, it checks if ‘!’ is a lowercase letter and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '2';
if (isxdigit(ch)) {
printf("%c is a hexadecimal digit.\n", ch);
} else {
printf("%c is not a hexadecimal digit.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘2’ is a hexadecimal digit
Explanation: The isxdigit() function in <ctype.h> checks if a character is a hexadecimal digit (0-9, a-f, A-F). In this case, it checks if ‘2’ is a hexadecimal digit and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '\n';
if (isprint(ch)) {
printf("%c is a printable character.\n", ch);
} else {
printf("%c is not a printable character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘\n’ is a control character
Explanation: The isprint() function in <ctype.h> checks if a character is a printable character (including alphanumeric characters and most punctuation). In this case, it checks if ‘\n’ (newline) is a printable character and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '>';
if (ispunct(ch)) {
printf("%c is a punctuation character.\n", ch);
} else {
printf("%c is not a punctuation character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘>’ is a punctuation character
Explanation: The ispunct() function in <ctype.h> checks if a character is a punctuation character (!”#$%&'()*+,-./:;<=>?@[\]^_`{|}~). In this case, it checks if ‘>’ is a punctuation character and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '\r';
if (iscntrl(ch)) {
printf("%c is a control character.\n", ch);
} else {
printf("%c is not a control character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘\r’ is a control character
Explanation: The iscntrl() function in <ctype.h> checks if a character is a control character (non-printable character, such as carriage return or newline). In this case, it checks if ‘\r’ (carriage return) is a control character and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '\t';
if (isspace(ch)) {
printf("%c is a whitespace character.\n", ch);
} else {
printf("%c is not a whitespace character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘\t’ is a whitespace character
Explanation: The isspace() function in <ctype.h> checks if a character is a whitespace character (space, tab, newline, etc.). In this case, it checks if ‘\t’ (tab) is a whitespace character and prints the corresponding message.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = '!';
if (isprint(ch)) {
printf("%c is a printable character.\n", ch);
} else {
printf("%c is not a printable character.\n", ch);
}
return 0;
}
Correct Answer: Checks if ‘!’ is a printable character
Explanation: The isprint() function in <ctype.h> checks if a character is a printable character (including alphanumeric characters and most punctuation). In this case, it checks if ‘!’ is a printable character and prints the corresponding message.
Correct Answer: time()
Explanation: The time() function in <time.h> is used to get the current calendar time (seconds since the Epoch).
Correct Answer: asctime()
Explanation: The asctime() function in <time.h> converts a broken-down time structure (struct tm) into a string representation of the form “Day Month Date HH:MM:SS Year\n”.
Correct Answer: localtime()
Explanation: The localtime() function in <time.h> converts a time_t value (calendar time) to a local time representation (struct tm).
#include <stdio.h>
#include <time.h>
int main() {
time_t now;
time(&now);
struct tm *local = localtime(&now);
printf("Current local time and date: %s", asctime(local));
return 0;
}
Correct Answer: Prints the current local time and date
Explanation: This code snippet uses localtime() to convert the current time (obtained from time()) to a local time representation and then prints it using asctime(), which formats the time structure as a string.
#include <stdio.h>
#include <time.h>
int main() {
time_t now;
time(&now);
struct tm *utc = gmtime(&now);
printf("Current UTC time and date: %s", asctime(utc));
return 0;
}
Correct Answer: Prints the current UTC time and date
Explanation: This code snippet uses gmtime() to convert the current time (obtained from time()) to Coordinated Universal Time (UTC) and then prints it using asctime(), which formats the time structure as a string.
#include <stdio.h>
#include <time.h>
int main() {
time_t rawtime;
struct tm *info;
time(&rawtime);
info = localtime(&rawtime);
printf("Current local time and date: %d/%d/%d %d:%d:%d\n",
info->tm_mday, info->tm_mon + 1, info->tm_year + 1900,
info->tm_hour, info->tm_min, info->tm_sec);
return 0;
}
Correct Answer: Prints the current local time and date in a specific format
Explanation: This code snippet uses localtime() to convert the current time (obtained from time()) to a local time representation and then prints it in a specific format using the fields of the tm structure.
#include <stdio.h>
#include <time.h>
int main() {
time_t rawtime;
struct tm *info;
time(&rawtime);
info = gmtime(&rawtime);
printf("Current UTC time and date: %d-%02d-%02dT%02d:%02d:%02dZ\n",
info->tm_year + 1900, info->tm_mon + 1, info->tm_mday,
info->tm_hour, info->tm_min, info->tm_sec);
return 0;
}
Correct Answer: Prints the current UTC time and date in ISO 8601 format
Explanation: This code snippet uses gmtime() to convert the current time (obtained from time()) to UTC and then prints it in ISO 8601 format, which is commonly used for representing date and time.
#include <stdio.h>
#include <time.h>
int main() {
time_t start, end;
double elapsed;
time(&start);
// Perform some operation
for (int i = 0; i < 1000000; ++i) {
// Do something
}
time(&end);
elapsed = difftime(end, start);
printf("Time taken to perform operation: %.2f seconds\n", elapsed);
return 0;
}
Correct Answer: Prints the time taken to perform a specific operation
Explanation: This code snippet uses difftime() to calculate the difference in time between the end and start times (measured using time()), representing the time taken to perform a specific operation.
#include <stdio.h>
#include <time.h>
int main() {
time_t current_time;
char* c_time_string;
current_time = time(NULL);
c_time_string = ctime(¤t_time);
printf("Current time and date: %s", c_time_string);
return 0;
}
Correct Answer: Prints the current local time and date
Explanation: This code snippet uses ctime() to convert the current time (obtained from time()) to a string representation of the local time and date, which is then printed using printf().
#include <stdio.h>
#include <time.h>
int main() {
time_t current_time;
char formatted_time[50];
struct tm * time_info;
time(¤t_time);
time_info = localtime(¤t_time);
strftime(formatted_time, sizeof(formatted_time), "%Y-%m-%d %H:%M:%S", time_info);
printf("Formatted date and time: %s\n", formatted_time);
return 0;
}
Correct Answer: Prints the formatted time string
Explanation: This code snippet uses strftime() to format the current local time (obtained from localtime()) into a specific format ("%Y-%m-%d %H:%M:%S") and stores it in the formatted_time array, which is then printed using printf().
#include <stdio.h>
#include <time.h>
int main() {
time_t current_time;
struct tm *time_info;
char buffer[80];
time(¤t_time);
time_info = localtime(¤t_time);
strftime(buffer, 80, "Today is %A, %B %d, %Y.", time_info);
printf("%s\n", buffer);
return 0;
}
Correct Answer: Prints the formatted date string with weekday and month
Explanation: This code snippet uses strftime() to format the current local time (obtained from localtime()) into a specific format that includes the weekday (%A), month (%B), day (%d), and year (%Y), then prints it.
#include <stdio.h>
#include <time.h>
int main() {
time_t now;
struct tm newyear;
double seconds;
time(&now); /* Get current time */
newyear = *localtime(&now);
newyear.tm_hour = 0;
newyear.tm_min = 0;
newyear.tm_sec = 0;
newyear.tm_mon = 0;
newyear.tm_mday = 1;
seconds = difftime(now,mktime(&newyear));
printf ("%.f seconds since New Year in the current timezone.\n", seconds);
return 0;
}
Correct Answer: Prints the number of seconds since the start of the current year
Explanation: This code snippet calculates the number of seconds between the current time and the start of the current year using difftime() and mktime(), then prints the result.
#include <stdio.h>
#include <time.h>
int main() {
time_t start, end;
double elapsed;
struct tm start_time, end_time;
time(&start);
localtime_r(&start, &start_time);
// Perform some operation
for (int i = 0; i < 1000000; ++i) {
// Do something
}
time(&end);
localtime_r(&end, &end_time);
elapsed = difftime(mktime(&end_time), mktime(&start_time));
printf("Time taken to perform operation: %.2f seconds\n", elapsed);
return 0;
}
Correct Answer: Prints the time taken to perform a specific operation
Explanation: This code snippet uses difftime(), mktime(), and localtime_r() to calculate the elapsed time between two time points and prints the result as the time taken to perform a specific operation.
#include <stdio.h>
#include <time.h>
int main() {
time_t rawtime;
struct tm *timeinfo;
int year, month, day;
const char *weekday[] = { "Sunday", "Monday",
"Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
time (&rawtime);
timeinfo = localtime (&rawtime);
printf ("Enter year: ");
scanf ("%d",&year);
printf ("Enter month: ");
scanf ("%d",&month);
printf ("Enter day: ");
scanf ("%d",&day);
timeinfo->tm_year = year - 1900;
timeinfo->tm_mon = month - 1;
timeinfo->tm_mday = day;
mktime ( timeinfo );
printf ("That day is a %s.\n", weekday[timeinfo->tm_wday]);
return 0;
}
Correct Answer: Prints the day of the week for a specified date
Explanation: This code snippet prompts the user to enter a specific date, then uses mktime() and localtime() to determine which day of the week that date falls on, printing the corresponding weekday.
#include <stdio.h>
#include <time.h>
int main() {
time_t current_time;
struct tm *time_info;
char formatted_time[50];
time(¤t_time);
time_info = localtime(¤t_time);
strftime(formatted_time, sizeof(formatted_time), "Today's date: %d/%m/%Y", time_info);
printf("%s\n", formatted_time);
return 0;
}
Correct Answer: Prints the formatted date string with day, month, and year
Explanation: This code snippet uses strftime() to format the current local time (obtained from localtime()) into a specific format that includes the day (%d), month (%m), and year (%Y), then prints it.
#include <stdio.h>
#include <time.h>
int main() {
time_t rawtime;
struct tm *info;
char buffer[80];
time(&rawtime);
info = gmtime(&rawtime);
strftime(buffer, 80, "UTC time: %Y-%m-%d %H:%M:%S", info);
printf("%s\n", buffer);
return 0;
}
Correct Answer: Prints the current UTC time
Explanation: This code snippet uses gmtime() to convert the current time (obtained from time()) to Coordinated Universal Time (UTC) and then formats it using strftime(), printing the formatted UTC time.
#include <stdio.h>
#include <time.h>
int main() {
time_t now;
struct tm new_year;
time(&now);
new_year = *localtime(&now);
new_year.tm_hour = 0;
new_year.tm_min = 0;
new_year.tm_sec = 0;
new_year.tm_mon = 0;
new_year.tm_mday = 1;
double seconds = difftime(now, mktime(&new_year));
printf ("%.f seconds since the start of the current year in the local timezone.\n", seconds);
return 0;
}
Correct Answer: Prints the number of seconds since the start of the current year
Explanation: This code snippet calculates the number of seconds between the current time and the start of the current year using difftime() and mktime(), then prints the result.
Correct Answer: malloc()
Explanation: The malloc() function in <stdlib.h> is used to allocate memory dynamically in C.
Correct Answer: Allocates memory for an array of elements, initializing them to 0
Explanation: The calloc() function in <stdlib.h> allocates memory for an array of elements and initializes them to 0.
Correct Answer: Reallocates memory blocks previously allocated by malloc() or calloc()
Explanation: The realloc() function in <stdlib.h> reallocates memory blocks previously allocated by malloc() or calloc().
Correct Answer: Frees allocated memory
Explanation: The free() function in <stdlib.h> is used to deallocate or free the memory previously allocated dynamically using malloc(), calloc(), or realloc().
Correct Answer: rand()
Explanation: The rand() function in <stdlib.h> is used to generate pseudo-random numbers in C.
Correct Answer: Initializes the random number generator with a seed
Explanation: The srand() function in <stdlib.h> initializes the random number generator with a seed, which is crucial for generating random sequences.
Correct Answer: exit()
Explanation: The exit() function in <stdlib.h> is used to terminate a C program and indicate a successful termination.
Correct Answer: Terminates the program and prints an error message
Explanation: The abort() function in <stdlib.h> terminates the program abnormally and optionally prints an error message.
Correct Answer: Executes a command as if you were at the operating system's command line
Explanation: The system() function in <stdlib.h> executes a command as if you were at the operating system's command line.
Correct Answer: strtol()
Explanation: The strtol() function in <stdlib.h> is used to convert a string to a long integer in C.
Correct Answer: Converts a string to an integer
Explanation: The atoi() function in <stdlib.h> converts a string to an integer in C.
Correct Answer: Converts a string to a floating-point number
Explanation: The atof() function in <stdlib.h> converts a string to a floating-point number (double) in C.
Correct Answer: Performs integer division and returns the quotient and remainder
Explanation: The ldiv() function in <stdlib.h> performs integer division on two long integers and returns a structure containing the quotient and remainder.
Correct Answer: Returns the absolute value of an integer
Explanation: The `abs()` function in `<stdlib.h>` returns the absolute value of an integer.
Correct Answer: Returns the absolute value of a long integer
Explanation: The `labs()` function in `<stdlib.h>` returns the absolute value of a long integer.
Correct Answer: Returns the absolute value of a long long integer
Explanation: The `llabs()` function in `<stdlib.h>` returns the absolute value of a long long integer.
Correct Answer: rand_range()
Explanation: There is no direct `rand_range()` function in `<stdlib.h>`. Typically, you would use `rand()` along with modulo operation to generate random numbers within a specified range.
Correct Answer: Sorts an array using the quicksort algorithm
Explanation: The `qsort()` function in `<stdlib.h>` sorts an array using the quicksort algorithm.
Correct Answer: Searches for an element in a sorted array
Explanation: The `bsearch()` function in `<stdlib.h>` searches for an element in a sorted array using binary search.
Correct Answer: Allocates memory for an array of elements, initializing them to 0
Explanation: The `calloc()` function in `<stdlib.h>` allocates memory for an array of elements and initializes them to 0.
Correct Answer: Registers a function to be called at program termination
Explanation: The `atexit()` function in `<stdlib.h>` registers a function to be called automatically when the program terminates.
Correct Answer: Retrieves the value of an environment variable
Explanation: The `getenv()` function in `<stdlib.h>` retrieves the value of an environment variable specified by its name.
Correct Answer: strtod()
Explanation: The `strtod()` function in `<stdlib.h>` is used to convert a string to a double in C.
Correct Answer: printf()
Explanation: The `printf()` function in `
Correct Answer: scanf()
Explanation: The `scanf()` function in `
Correct Answer: Reads a line of text from a file
Explanation: The `fgets()` function in `
Correct Answer: Prints a string to the standard output
Explanation: The `puts()` function in `
Correct Answer: Prints a formatted string to a file
Explanation: The `fprintf()` function in `
Correct Answer: Reads a formatted input from a file
Explanation: The `fscanf()` function in `
Correct Answer: Positions the file pointer at the beginning of a file
Explanation: The `rewind()` function in `
Correct Answer: Tests the end-of-file indicator for a file
Explanation: The `feof()` function in `
Correct Answer: fopen()
Explanation: The `fopen()` function in `
Correct Answer: fclose()
Explanation: The `fclose()` function in `