Find Output Of Program

Question 11 :

What will be the output of the program ?

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

int main()
{
    static char str1[] = "dills";
    static char str2[20];
    static char str3[] = "Daffo";
    int i;
    i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills");
    printf("%d\n", i);
    return 0;
}


A). 0
B). 1
C). 2
D). 4
Answer : Option A

Question 12 :

What will be the output of the program ?

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

int main()
{
    static char s[] = "Hello!";
    printf("%d\n", *(s+strlen(s)));
    return 0;
}


A). 8
B). 0
C). 16
D). Error
Answer : Option B

Question 13 :

What will be the output of the program ?

#include < stdio.h >

int main()
{
    static char s[25] = "The cocaine man";
    int i=0;
    char ch;
    ch = s[++i];
    printf("%c", ch);
    ch = s[i++];
    printf("%c", ch);
    ch = i++[s];
    printf("%c", ch);
    ch = ++i[s];
    printf("%c", ch);
    return 0;
}


A). hhe!
B). he c
C). The c
D). Hhec
Answer : Option A

Question 14 :

What will be the output of the program in 16-bit platform (Turbo C under DOS) ?

#include < stdio.h >

int main()
{
    printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));
    return 0;
}


A). 8, 1, 4
B). 4, 2, 8
C). 4, 2, 4
D). 10, 3, 4
Answer : Option B

Explanation :

Step 1:
printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));
The sizeof function returns the size of the given expression.
sizeof(3.0f) is a floating point constant. The size of float is 4 bytes
sizeof('3') It converts '3' in to ASCII value.. The size of int is 2 bytes
sizeof(3.0) is a double constant. The size of double is 8 bytes

Hence the output of the program is 4,2,8
Note: The above program may produce different output in other platform due to the platform dependency of C compiler.
In Turbo C, 4 2 8. But in GCC, the output will be 4 4 8.


Question 15 :

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 empty\n");
    else
        printf("The string is not empty\n");
    return 0;
}


A). The string is empty
B). The string is not empty
C). No output
D). 0
Answer : Option B

Explanation :

The function printf() returns the number of charecters printed on the console.

Step 1: char a[] = "\0"; The variable a is declared as an array of characters and it initialized with "\0". It denotes that the string is empty.
Step 2: if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero). Hence the if condition is failed.

In the else part it prints "The string is not empty".