From the course: Secure Coding in C

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Working with string literals

Working with string literals - C Tutorial

From the course: Secure Coding in C

Start my 1-month free trial

Working with string literals

- [Instructor] A string literal is text in double quotes. It can appear within a specific function, or be defined on its own for multiple uses. In this code, you see a common method for declaring a string literal. At line five the prompt pointer references the string, press any key. This method of declaring a string literal is common, and I use it, but it has a few quirks, one of which is that the pointer references memory in a different way than had you allocated it yourself. One solution is to make the string a constant, as shown in line five in this code. As a constant, the string can't be modified, which is okay for a string literal. Still, an allocation problem looms in the code. The best solution is to use array notation to reference the string literal, as shown here at line five. You could even make this declaration constant as well, though the big difference is that the string is accessible within your code, just…

Contents