Strings

6

What will be the output of the program ?

#include<stdio.h>
#include<string.h>

int main()
{
    printf("%c\n", "abcdefgh"[4]);
    return 0;
}
A. Error
B. d
C. e
D. abcdefgh

7

What will be the output of the program ?

#include<stdio.h>
int main()
{
    char str1[] = "Hello";
    char str2[] = "Hello";
    if(str1 == str2)
        printf("Equal\n");
    else
        printf("Unequal\n");
    return 0;
}
A. Equal
B. Unequal
C. Error
D. None of above

8

What will be the output of the program ?

#include<stdio.h>
#include<string.h>

int main()
{
    char str1[5], str2[5];
    int i;
    gets(str1);
    gets(str2);
    i = strcmp(str1, str2);
    printf("%d\n", i);
    return 0;
}
A. Unpredictable integer value
B. 0
C. -1
D. Error

9

What will be the output of the program ?

#include<stdio.h>
int main()
{
    int i;
    char a[] = "\0";
    if(printf("%s", a))
        printf("The string is not empty\n");
    else
        printf("The string is empty\n");
    return 0;
}
A. The string is not empty
B. The string is empty
C. No output
D. 0

10

If the size of pointer is 4 bytes then What will be the output of the program ?

#include<stdio.h>
int main()
{
    char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"};
    printf("%d, %d", sizeof(str), strlen(str[0]));
    return 0;
}
A. 22, 4
B. 25, 5
C. 24, 5
D. 20, 2