The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C Strings

You will need to use character strings in most of your program - names, address, state, district and so on. Thus understanding about strings in C programming is necessary. The following four points are good enough to make use of strings

  • In C, strings are arrays of characters.
  • Every string in a c program is ends with '\0' character.
  • Strings are always enclosed within double quotes.
  • If the program uses the string functions, it must define the header file string.h.

Syntax - Strings

Syntax
char str[12] = "ThisisString";

Program - Strings

strings.c
#include <stdio.h>
int main()
{
char nation[20] = "2Braces India";
printf("%s", nation);
return 0;
}
  • 2Braces India

Note:

The program prints the string stored in a variable 'nation'. The above program don't require the header file "string.h", because there is no string functions.

What Is String Literals

We have already made extensive use of string literals for output. Just about every time the printf() method or function was used in the above example too, we used a string literal as the argument. A string literal is nothing more than a sequence of characters between double quotes.
"This is a string literal"

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report