Machine-translated by Google. Questions are authored in English.
Top

Strings Questions and Answers

Answer: A

Correct answer: int strcoll(const char *s1,const char *s2)

strcoll compares two strings, so it takes two const char * arguments and returns an int in the manner of strcmp. The const qualifiers state that neither string is modified.

Please log in or register to report this question.

82.

NULL is the macro defined in the header string. h.

Answer: A

Correct answer: true

NULL, the null pointer constant, is defined in several headers, and <string.h> is one of them - along with <stdio.h>, <stdlib.h>, <stddef.h> and others. Repeating the definition is harmless because it is identical each time, so a program gets NULL from whichever header it happens to include.

Please log in or register to report this question.

Answer: A

Correct answer: compares the string, result is dependent on the LC_COLLATE

strcoll compares two strings according to the collating sequence of the current locale, set by LC_COLLATE. That matters wherever sorting order is not simply the order of the character codes - accented letters in French, or the treatment of case - which is exactly where strcmp gives the wrong answer for a human reader.

Please log in or register to report this question.

84.

#include <stdio.h> 
int main() 
{ 
    char str[] = "GeeksQuiz"; 
    printf("%s %s %s\n", &str[5], &5[str], str+5); 
    printf("%c %c %c\n", *(str+6), str[6], 6[str]); 
    return 0; 
} 

 

Answer: D

Correct answer: Quiz Quiz Quiz u u u

Subscripting is defined as a[i] == *(a + i), and since addition commutes, i[a] means the same thing. So &str[5], &5[str] and str+5 are all the address of the sixth character - each prints Quiz. Likewise *(str+6), str[6] and 6[str] are all the character u.

Please log in or register to report this question.

85.

Assume that a character takes 1 byte. Output of following program?

#include <stdio.h> 
int main() 
{ 
    char str[20] = "GeeksQuiz"; 
    printf ("%d", sizeof(str)); 
    return 0; 
} 

 

Answer: C

Correct answer: 20

sizeof reports the size of the array as declared, not the length of the string in it. The array was given 20 elements, so the answer is 20, of which the first ten hold "GeeksQuiz" and its null and the remaining ten are zero-filled. strlen(str) would give 9.

Please log in or register to report this question.

86.

Output?

int main() 
{ 
    char a[2][3][3] = {'g','e','e','k','s','q','u','i','z'}; 
    printf("%s ", **a); 
    return 0; 
} 

 

Answer: C

Correct answer: geeksquiz

The array is 2×3×3 = 18 bytes in one contiguous block. The nine initialisers fill the first nine, and the remaining bytes are zero-filled, as a partly initialised array always is. **a is the address of the first byte, and %s prints from there to the first null - which is byte 10. So the whole run of nine characters comes out, with no garbage after it.

Please log in or register to report this question.

87.

What return types are used by the string operations?

Answer: D

Correct answer: void, int and (char *) only

The string functions return one of three things: char * for those that produce a position or a destination (strcpy, strcat, strchr, strstr), int for the comparisons (strcmp, strncmp), and void * for the mem family. strlen returns size_t, an unsigned integer type.

Please log in or register to report this question.

88.

What will be the output of the program If characters 'a', 'b' and 'c' enter are supplied as input?

#include <stdio.h>

int main()
{
    void fun();
    fun();
    printf("\n");
    return 0;
}
void fun()
{
    char c;
    if((c = getchar())!= '\n')
        fun();
    printf("%c", c);
}

 

Answer: D

Correct answer: cba

fun reads a character and, if it is not the newline, calls itself before printing. So the three calls stack up, each holding its own c, and the printing happens as the recursion unwinds - last character first. With a, b, c entered, the output is cba.

Please log in or register to report this question.

89.

What will be the output of the program ?

#include <stdio.h>

int main()
{
    printf("India", "BIX\n");
    return 0;
}

 

Answer: C

Correct answer: India

printf takes a variable number of arguments and uses only as many as its format string calls for. "India" contains no conversion specifier, so the second argument is simply ignored and the output is India. (Too few arguments would be undefined behaviour; too many is harmless.)

Please log in or register to report this question.

90.

What will be returned by the following C code?

size_t strlen(const char *s)
{
    const char *sc;
    for (sc = s; *sc != '\0'; ++sc)
        ;
    return (sc - s);
}

Answer: B

Correct answer: length of string s

This is the textbook implementation of strlen. The pointer sc starts at the beginning and advances until it meets the terminating null; the difference sc - s is then the number of characters before it - that is, the length of the string, not counting the null. Pointer subtraction gives a count of elements, which for char is a count of bytes.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Strings Questions and Answers || Strings MCQ Questions and Answers || Strings GK Questions and Answers || Strings GK MCQ Questions || Strings Multiple Choice Questions and Answers || Strings GK || GK on Strings || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming