By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

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

P: 1
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 ?
Feb 16 '19 #1
Share this Question
Share on Google+
1 Reply


dev7060
P: 39
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:

Expand|Select|Wrap|Line Numbers
  1.     char y = 'X';
  2.     cout<<sizeof(y);
  3.  
---------------------------------------
Expand|Select|Wrap|Line Numbers
  1.     char y[]= "X";
  2.     cout<<sizeof(y);
  3.  
4 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.