Solution for Exercise 7-10

ex0710

#include <stdio.h>

int main()
{
    char prompt[] = "Press Enter to explode:";

    printf("%s",prompt);
    getchar();
    return(0);
}

Output

Press Enter to explode:

Notes

* The square brackets at Line 5 are empty. Sometimes the brackets, so close together, appear as a square symbol. That's not the case in the C language; what you see are the [ and ] characters close together.

* Normally an array in C features a value between the two brackets, such as:

* The number in the brackets indicates the number of characters in the string (elements in the array). When you leave the brackets blank, the compiler calculates the string length for you, which is what happens in this Exercise.

* Most programmers leave the square brackets empty when they declare a string as shown above.

* All the text between the double quotes at Line 5 is assigned to the prompt char array.

* It's okay to refer to prompt as a "string variable." While the C language doesn't have a string data type, it does use string variables.

* The %s is the string conversion character.