C Programming - Strings - Discussion

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

int main()
{
    char str[] = "India\0\BIX\0";
    printf("%s\n", str);
    return 0;
}
BIX
India
India BIX
India\0BIX
Answer: Option
Explanation:

A string is a collection of characters terminated by '\0'.

Step 1: char str[] = "India\0\BIX\0"; The variable str is declared as an array of characters and initialized with value "India"

Step 2: printf("%s\n", str); It prints the value of the str.

The output of the program is "India".

Discussion:
4 comments Page 1 of 1.

Himanshu said:   1 decade ago
String will be made till where they first null character will be encountered.

Satish Dalvi said:   1 decade ago
It will print only India because after last character 'a' \0 is detected. This indicates the termination of the string.

Ram said:   1 decade ago
What is the length of string "india\0bix\0"?

Dhaivat said:   1 decade ago
Length of string "india\0bix\0" return 5.

Post your comments here:

Your comments will be displayed after verification.