saving . . . saved Unexpected Output has been deleted. Unexpected Output has been hidden .
Unexpected Output
Title
Question
#include<stdio.h>
#include<string.h>
int main()
{
<span style="white-space: pre;">\t</span>
  char strname[30]="Spoken-Tutorial";
<span style="white-space: pre;">\t</span>char s[]={'a','b','c'};
  printf("The string is %s\\n", strname);
<span style="white-space: pre;">\t</span>printf("String: %s\\n",s); 
  return 0;
}

For the above code output is following:
The string is Spoken-Tutorial
String: abcSpoken-Tutorial

Why string s is containing such value?


C-and-Cpp Strings 02-03 min 10-20 sec 29-02-20, 3:13 p.m. Himani.Parekh

Answers:

In C you need to terminate a string with a 'null' character.  The above program can also produce a segmentation fault on some machines, as the string s is not null terminated.
29-02-20, 4:20 p.m. bhaskar76


Log-in to answer to this question.