declare a string in C
Code snippet on how to declare a string in C
char greeting[20] = "Hello World";
This code declares a string called “greeting” to store 20 characters in C. The 20 characters are the string “Hello World”, which has 11 letters and 9 spaces. The char data type is used to declare string variables in C, and is necessary for the string to be stored in memory so that it can be used by the program. The square brackets ([ ]) after the data type indicate that the variable is an array, meaning that it can contain multiple characters. By locking the size of the array at 20 characters, any string assigned to the variable must fit in the 20 character limit or it will be cut off. As a result, “Hello World” is the longest string that can be assigned to the greeting variable.