String Constants - C String

C examples for String:char array

Introduction

C supports string constant.

A string is a list of characters enclosed in double quotes.

For example, "this is a test" is a string.

Although C can define string constants, it does not formally have a string data type.

A single character constant is enclosed in single quotes, as in 'a'. "a" is a string containing only one letter.

Backslash Character Constants

C includes the special backslash character constants.

These are also referred to as escape sequences.

For example, the following program outputs a new line and a tab and then prints the string This is a test .

Code Meaning
\b Backspace
\f Form feed
\n New line
\r Carriage return
\t Horizontal tab
\" Double quote
\' Single quote
\\ Backslash
\v Vertical tab
\a Alert
\? Question mark
\N Octal constant (where N is an octal constant)
\xN Hexadecimal constant (where N is a hexadecimal constant)

Demo Code

#include <stdio.h>

int main(void)
{
   printf("\n\tThis is a test.");

   return 0;//from  w w w  .  j  a va  2  s.  co m
}

Result


Related Tutorials