C Programming - Strings - Discussion

Discussion Forum : Strings - Find Output of Program (Q.No. 8)
8.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    char str[7] = "IndiaBIX";
    printf("%s\n", str);
    return 0;
}
Error
IndiaBIX
Cannot predict
None of above
Answer: Option
Explanation:
Here str[] has declared as 7 character array and into a 8 character is stored. This will result in overwriting of the byte beyond 7 byte reserved for '\0'.
Discussion:
12 comments Page 2 of 2.

Naman_Shah said:   9 years ago
According to me,

Output is IndiaBi, because the array initialize up to 7 characters. So the Answer should be option 'D' because IndiaBi is not mentioned.

Thank you!!!

Amit kumar said:   3 years ago
This programs gives the output as IndiaBI.

So, the correct option is D.


Post your comments here:

Your comments will be displayed after verification.