-5
#include<stdio.h>
int main()
{
      char *value[] = {'Godnull'};
      printf("%s\n",value);
      return 0;
}

Output: llun

Could someone please explain this output.

2 Answers2

1

Writing a string in single quotes is absolutely fine in C. These are called "MultiCharacter Constant" which is of Type "int". And depends on the compiler int will be having size of 4 Bytes which can store 4(1 Byte Characters) into your array. Probably that might be the reason why you are getting only four characters printed on the console. Please refer this Multiple characters in a character constant

Anyhow it is not suggested to declare the array of character pointers as above.

Thanks,

Community
  • 1
  • 1
Siva Makani
  • 196
  • 2
  • 17
0

You've got a few problems here:

 char *value[] = {'Godnull'};

You are creating an array of strings, when I'm assuming that you are attempting to create a single string

Additionally, to initialize a string, you want the string in double-quotes:

  char *value = "Godnull";

Edit: If you really want to declare this as a character array and use it as a string, try:

 char value[] = {'G', 'o', 'd', 'n', 'u', 'l', 'l', '\0'};
Don Shankin
  • 440
  • 3
  • 10