-
Notifications
You must be signed in to change notification settings - Fork 0
C_Strings.c
ani9977 edited this page Sep 11, 2024
·
1 revision
Here's the updated C code with added documentation and an explanation:
#include <stdio.h>
/**
* @brief The main function demonstrates basic string handling in C.
*
* This function initializes a character array with a string and prints it.
*
* @return int Returns 0 to indicate successful execution.
*/
int main() {
char str[] = "Hello, World!"; /**< Character array initialized with the string "Hello, World!". */
// Print the string
printf("String: %s\n", str);
return 0; /**< Return 0 to indicate successful execution. */
}-
String Initialization:
-
char str[] = "Hello, World!";declares a character arraystrand initializes it with the string"Hello, World!". In C, string literals are automatically null-terminated, which means the array will include a null character'\0'at the end.
-
-
Printing the String:
-
printf("String: %s\n", str);prints the string stored in thestrarray. The%sformat specifier is used for printing strings in C.
-
-
Return Statement:
-
return 0;indicates that the program has executed successfully. The value0is returned to the operating system.
-