![]() |
In C++, we can also define a character array as a member of a structure for storing strings. In this article, we will discuss how to initialize a char array in a struct in C. Initialization of Char Array in Struct in CWhen we create a structure instance (variable) in C that includes a char array, we can set an initial value for that char array directly using the list initialization. Syntaxstruct StructName structVariable = { "string value"};
But we can only initialize using this method in the declaration of the variable. If we initialize them after declaration, we have to use the strcpy() function. C Program to Initialize Char Array in StructThe below example demonstrates the initialization of a char array in structure. C
Output
Person 1 Name: Jack Person 2 Name: Roman |
Reffered: https://www.geeksforgeeks.org
C Language |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |