if 'X' is occupied 1 byte then how many bytes occupied by "X" ? I want to know that E

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • junti pachani
    New Member
    • Feb 2019
    • 1

    if 'X' is occupied 1 byte then how many bytes occupied by "X" ? I want to know that E

    if 'X' is occupied 1 byte then how many bytes occupied by "X" ? I want to know that Exactly how many bytes occupied by a String type character ?
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Single quote refers to a single character. Double quote makes it a string literal. The size of a string is: number of characters*size of each char plus 1 (of the terminator). Terminator is present at the end of a string. It is '\0' , called NUL in ASCII.
    Let's consider char X takes 1 byte. Therefore:
    'X' = 1 byte
    "X" = 2 bytes

    You can check these values as well, like:

    Code:
        char y = 'X';
        cout<<sizeof(y);
    ---------------------------------------
    Code:
        char y[]= "X";
        cout<<sizeof(y);

    Comment

    Working...