From the course: Secure Coding in C

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Working with string literals

Working with string literals - C Tutorial

From the course: Secure Coding in C

Working with string literals

- [Instructor] Here you see a string literal. It's text in double quotes, which can appear within a specific function, or it can be defined on its own for multiple uses. The string literal is assigned to the pointer prompt, which references the strings address in memory. This method of declaring a string literal is common. 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. It's best to use this string without modification, which can lead to trouble in other functions elsewhere in the code. So one solution is to make the string a constant. As a constant, the string can't be modified, which is okay for a string literal. The best solution, however, is to use a ray notation to reference such a string literal. You could make this declaration a constant as well, though the big difference is that the string is accessible elsewhere within your code, just in case you plan on doing something with it. To…

Contents