C String Test 11) Which of the function is more appropriate for reading a multi-word string?
The correct option is (b). Explanation: The function gets() is used for collecting a string of characters terminated by new line from the standard input stream stdin. Therefore gets() is more appropriate for reading a multi-word string. 2) Which library function can change an unsigned long integer to a string?
The correct option is (c). Explanation: The function ultoa() is used for converting an unsigned long integer to a string. 3) What is the value return by strcmp() function when two strings are the same?
The correct option is (c). Explanation: C library function strcmp() compares the two strings with each other and the value is return accordingly. Comparison occurs between a first string (str1) with a second string (str2). On comparing the two string, the values return by a function strcmp() are:
4) What is built in library function for comparing the two strings?
The correct option is (a). Explanation: The strcmp() is a built-in function available in "string.h" header file. It is used for comparing the two strings. It returns 0 if both are same strings. It returns positive value greater than 0 if first string is greater than second string, otherwise it returns negative value. 5) What will be the output of the below program?
The correct option is (c). Explanation: Step 1: char a[] = "%d\n"; The variable 'a' is declared as an array of characters and initialized with string "%d". Step 2: a[1] = 'b'; Here, we overwrite the second element of array ?a? by 'b'. Hence the array ?a? becomes "%c". Step 3: printf(a, 65); becomes printf("%c", 65); Therefore it will print the ASCII value of 65. Hence the output is 'A'. |