C Programming Structures Containing Arrays, Pointers, and Strings

Last modified by Microchip on 2023/11/09 09:07

Strings:

  • May be assigned directly to char array member only at the declaration.

  • May be assigned directly to a pointer to a char member at any time.

Example: Structure

1 struct strings
2 {
3  char a[4];    
4  char *b;    
5 } str;

Example: Initializing Members

1 int main(void)
2 {
3   str.a[0] = 'B';
4  str.a[1] = 'a';
5  str.a[2] = 'd';
6  str.a[3] = '\0';
7
8  str.b = "Good";