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;
}
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.
Dhaivat said:
1 decade ago
Length of string "india\0bix\0" return 5.
Ram said:
1 decade ago
What is the length of string "india\0bix\0"?
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.
Himanshu said:
1 decade ago
String will be made till where they first null character will be encountered.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers