All of its bits 0s the null terminator occupies the

  • No School
  • AA 1
  • S-Abdelrahman
  • 2

This preview shows page 1 - 2 out of 2 pages.

All of its bits 0's. The null terminator occupies the first position in the ASCIIand EBCDICcollating sequences. The index identifying the null terminator element is the same as the number of meaningful characters in the string. charname01234567891011121314151617MynameisArnold\0The number of memory locations occupied by a string is one more than the number of meaningful characters in the string. Allocating MemoryWe allocate memory for a string in the same way that we allocate memory for an array. Since the null terminator is one of the elements in the array, we allocate memory for one character more than the number of meaningful characters. For example, to allocate memory for a string with up to 30 meaningful characters, we write
Background image
char name[31]; // 30 chars plus 1 char for the terminator Initializing MemoryTo initialize a string at the time of memory allocation, we follow the definition with the assignment operator and the set of initial characters enclosed in braces. const char name[31] = {'M','y',' ','n','a','m','e',' ','i','s',' ', 'A','r','n','o','l','d','\0'};
Background image

You've reached the end of your free preview.

Want to read both pages?

  • Fall '19

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture