Friday 10 November 2017

Strings Questions in C

-----------------------------------------------------------------------------------------------------------
Previous Page                     Home                       Last Page
-----------------------------------------------------------------------------------------------------------

15.
What is the output of this C code?

    #include
    int main()
    {
        char *str = "hello, world";
        char *str1 = "hello, world";
        if (strcmp(str, str1))
            printf("equal");
        else
            printf("unequal");
    }
A. equal
B. unequal
C. Compilation error
D. Depends on the compiler

Answer: B
-----------------------------------------------------------------------------------------------------------

16.
What is the output of this C code?

    #include
    #include
    int main()
    {
        char *str = "hello, world";
        char str1[9];
        strncpy(str1, str, 9);
        printf("%s %d", str1, strlen(str1));
    }
A. hello, world 11
B. hello, wor 9
C. Undefined behaviour
D. Compilation error

Answer: C
-----------------------------------------------------------------------------------------------------------

17.
The return-type used in String operations are.

A. void only
B. void and (char *) only
C. void and int only
D. void, int and (char *) only

Answer: D
-----------------------------------------------------------------------------------------------------------

18.
What is the output of this C code?

    #include
    int main()
    {
        char str[10] = "hello";
        char *p = strrchr(str, 'l');
        printf("%c\n", *(++p));
    }

A. l
B. o
C. e
D. Compilation error

Answer: B
---------------------------------------------------------------------------------------------------------
Previous Page               Home                Last Page 
---------------------------------------------------------------------------------------------------------

More Imp Topics:

Array
Preprocessor
Structures
Control Structures
Switch Case
Printf
Variables
File Handling

100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...