1) Which function is more appropriate for reading a multi-word string?
- gets
- printf
- scanf
Explanation:
The gets function is employed to gather a sequence of characters that ends with a newline character from the standard input stream stdin.
Thus, gets is better suited for retrieving a string containing multiple words.
2) Which library function can change an unsigned long integer to a string?
- system
- ltoa
- ultoa
- unsigned long can't be change into a string
Explanation:
The ultoa function is employed to convert an unsigned long integer into a string.
3) What is the value return by strcmp function when two strings are the same?
- Error
Explanation:
The C library function strcmp is utilized to compare two strings and returns a value based on their relationship.
int strcmp (const char *str1, const char *str2)
A comparison is made between the first string (str1) and a second string (str2).
On comparing the two string, the values return by a function strcmp are:
- If, str1 is equal to str2 then Return value = 0
- If, str1 is greater than str2 then Return value > 0
- If, str1 is less than str2 then Return value < 0
- strcmp
- equals
- str_compare
- string_cmp
4) What is built in library function for comparing the two strings?
Explanation:
The strcmp function is a predefined function found in the "string.h" header file. Its purpose is to compare two strings, with a return value of 0 indicating identical strings. In cases where the first string is considered greater than the second, a positive value above 0 is returned; conversely, a negative value is returned if the second string is greater.
5) What will be the output of the below program?
#include<stdio.h>
int main()
{
char a[] = "%d\n";
a[1] = 'b';
printf(a, 65);
return 0;
}
Explanation:
Step 1: Define a character array 'a' with the string "%d\n" assigned to it for initialization purposes.
By executing Step 2, the element at index 1 in array ?a? is updated to 'b'. Consequently, the array ?a? transforms to "%c".
Step 3: printf(a, 65); becomes printf("%c", 65);
Consequently, it will display the ASCII value corresponding to 65, resulting in the output being 'A'.