Initialize a string variable when you declare it - C String

C examples for String:char array

Description

Initialize a string variable when you declare it

Demo Code

#include <stdio.h>

int main(void)
{
  char saying[] = "This is a string.";

  printf("\nThe message is: %s", saying);
  
  printf("The character \0 is used to terminate a string.");
  return 0;/*from w ww  . j a v a  2s .  com*/
}

Result

You haven't explicitly defined the array dimension.

The compiler will assign a value to the dimension that is sufficient to accommodate the initializing string constant.

The total length are the sum of the number of characters and an extra element for the terminating \0.


Related Tutorials