in such casesthe compiler creates an array of size stores "helloin it and finally terminates the string with null character rest of the elements in the array are automatically initialized to null now consider the following statementschar str[ ]str "hello"the above initialization statement is illegal in and would generate compile-time error because of two reasons firstthe array is initialized with more elements than it can store secondinitialization cannot be separated from declaration reading strings if we declare string by writing char str[ ]then str can be read by the user in three ways using scanf function using gets(functionand using getchar(),getch()or getche(function repeatedly strings can be read using scanf(by writing scanf("% "str)although the syntax of using scanf(function is well known and easy to usethe main pitfall of using this function is that the function terminates as soon as it finds blank space for exampleif the user enters hello worldthen the str will contain only hello this is because the moment blank space is encounteredthe string is terminated by the scanf(function you may also specify field width to indicate the maximum number of characters that can be read remember that extra characters are left unconsumed in the input buffer unlike intfloatand char values% format does not require the programming tip ampersand before the variable str using operand with string the next method of reading string is by using the gets(function variable in the scanf statement the string can be read by writing generates an error gets(str)gets(is simple function that overcomes the drawbacks of the scanf(function the gets(function takes the starting address of the string which will hold the input the string inputted using gets(is automatically terminated with null character strings can also be read by calling the getchar(function repeatedly to read sequence of single characters (unless terminating character is enteredand simultaneously storing it in character array as shown below = ;(ch getchar;/get character while(ch !'*'str[ich;/store the read character in str ++ch getchar();/get another character str[ '\ ';/terminate str with null character note that in this methodyou have to deliberately append the string with null character the other two functions automatically do this