C Programming Language
  • Home
  • C Fundamentals
    • C Character Set
    • Tokens>
      • Keywords
      • Identifiers
      • Constants>
        • Definition and Its types
        • Numeric Constants>
          • Integer Constants
          • Real Constants
        • Character Constants
        • String Constants
        • Backslash Character
      • Operators>
        • Definition and Its types
        • Arithmetic
        • Relational
        • Logical
        • Increment
        • Decrement
        • Assignment
        • Arithmetic Assignment
        • Conditional
        • Bitwise
        • Special Operators
        • Hierarchy
    • Data Types>
      • Primary (Or) Basic
      • User-Defined
      • Derived
    • Variable>
      • Definition
      • Declaration
      • Initialization
  • Control Structures
    • Decision-Control>
      • If Statement>
        • Simple-if Statement
        • if-else Statement
        • Nested-if Statement
        • if-else ladder Statement
      • Switch Statement
    • Loop Control>
      • For
      • While
      • Do-While
  • Arrays
    • Introduction
    • Single-Dimensional>
      • Definition
      • Declaration
      • Initialization
    • Two-Dimensional>
      • Definition
      • Declaration
      • Initialization
    • Multi-Dimensional>
      • Definition
      • Declaration
      • Initialization
  • Functions
    • Definition
    • Standard Library Character Functions
    • Standard Library String Functions
    • Storage Classes>
      • Definition
      • Automatic
      • Register
      • Static
      • External
  • Pointers
  • Files
    • Concepts
    • Data Files and its Categories
    • Standard Files and its Categories
  • University Questions
    • April 2001 To 2005
    • April 2006 To 2010
    • April 2011 To 2015
    • November 2001 To 2005
    • November 2006 To 2010
    • November 2011 To 2015

String Constant
  •         A character string, a string constant consists of a sequence of characters enclosed in double quotes.
  •         A string constant may consist of any combination of digits, letters, escaped sequences and spaces.  Note that a character constant ۥAۥ
                  and the corresponding single character string constant "A" are not equivalent.

                 ۥAۥ        -           Character constant   -           ۥAۥ
                "A"       -           String Constant           -           ۥAۥ        and ۥ \0ۥ (NULL)

                The string constant "A" consists of character A and \0. However, a single character string constant does not have an equivalent integer value. It occupies two        
                bytes, one for the ASCII code of A and another for the NULL character with a value 0, which is used to terminate all strings.

                Valid String Constants: -                "W"                 "100"              "24, Kaja Street"

                Invalid String Constants: -             "W              the closing double quotes missing
                                                                            Raja"         the beginning double quotes missing

Rules for Constructing String constants

1)        A string constant may consist of any combination of digits, letters, escaped sequences and spaces enclosed in double quotes.
2)        Every string constant ends up with a NULL character which is automatically assigned (before the closing double quotation mark) by the compiler.

Difference between single character constant and string constant

                                Character Constant                                                                                                                               String Constant

A character constant is enclosed within single inverted commas.                                         A sequence of characters enclosed in double quotes

The maximum length of a character constant can be one character.                                     A string constant can be any length.

A single character string constant has an equivalent integer value.                                       A single character string constant does not have an equivalent integer value.

The character constant ‘A’ consists of only character A.                                                           The string constant "A" consists of character A and \0.

A single character constant occupies one byte.                                                                          A single string constant occupies two bytes

Every character constant does not end up with a NULL character.                                         Every string constant ends up with a NULL character which is automatically
                                                                                                                                                              assigned (before the closing double quotation mark) by the compiler

Questions
  1. Define String Constant? Give example.
  2. State the rules for constructing string constants


Powered by Create your own unique website with customizable templates.