Structures Containing Arrays, Pointers and Strings
Strings:
- May be assigned directly to char array member only at declaration
- May be assigned directly to a pointer to char member at any time
Example: Structure
|
1
2
3
4
5
|
struct strings{ char a[4]; char *b; } str; |
Example: Initializing Members
|
1
2
3
4
5
6
7
8
|
int main(void){ str.a[0] = ‘B’; str.a[1] = ‘a’; str.a[2] = ‘d’; str.a[3] = ‘\0’; str.b = “Good”; |