Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7922193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:52:16+00:00 2026-06-03T16:52:16+00:00

size of char is : 2 ( msdn ) sizeof(char) //2 a test :

  • 0

size of char is : 2 (msdn)

sizeof(char)  //2

a test :

char[] c = new char[1] {'a'};

Encoding.UTF8.GetByteCount(c) //1 ?

why the value is 1?

(of course if c is a unicode char like ‘ש’ so it does show 2 as it should.)

a is not .net char ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:52:18+00:00Added an answer on June 3, 2026 at 4:52 pm

    It’s because ‘a’ only takes one byte to encode in UTF-8.

    Encoding.UTF8.GetByteCount(c) will tell you how many bytes it takes to encode the given array of characters in UTF-8. See the documentation for Encoding.GetByteCount for more details. That’s entirely separate from how wide the char type is internally in .NET.

    Each character with code points less than 128 (i.e. U+0000 to U+007F) takes a single byte to encode in UTF-8.

    Other characters take 2, 3 or even 4 bytes in UTF-8. (There are values over U+1FFFF which would take 5 or 6 bytes to encode, but they’re not part of Unicode at the moment, and probably never will be.)

    Note that the only characters which take 4 bytes to encode in UTF-8 can’t be encoded in a single char anyway. A char is a UTF-16 code unit, and any Unicode code points over U+FFFF require two UTF-16 code units forming a surrogate pair to represent them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I structures like the following typedef struct { char *ptr; size_t used; size_t size;
Suppose I have the following code: void* my_alloc (size_t size) { return new char
The code is char** p = (char **) malloc(sizeof(char **) * size); //Where size
Are there machines (or compilers), where sizeof(char) != 1 ? Does C99 standard says
#define HISTORY_SIZE 50 #define INPUT_SIZE 512 /*Max input size*/ char input[INPUT_SIZE]; /*Holding user input
I need to read char[] (size is COUNT) from text file from OFFSET with
static char st[][8192]; void foo ( int tab_size){ st = (char**) malloc ((tab_size+1)*sizeof(char)*8192); }
I have allocated a chunk of memory of type char and size is say
What is the difference between void *bytes = alloca(size); and char bytes[size]; //Or to
A Java char is 2 bytes (max size of 65,536) but there are 95,221

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.