Interviews - C# Corner

MD SHAMSE ALAM
int is 2 byte and char 4 byte why?
By MD SHAMSE ALAM in C# onJun 16 2015
  • Jason Wilczak
    Jul, 2015 7

    Char: It is 2 bytes in C# because .NET uses UTF-16 for strings (UTF-32 would be 4 bytes). Almost all possible characters in human language can be expressed with 2 bytes (all English letters only require 1 byte) - SO Post: http://stackoverflow.com/questions/6781886/why-do-char-takes-2-bytes-as-it-can-be-stored-in-one-byteInt: This is 4 bytes (Int32). The only 2 byte numerical value in .Net is a short, which is (Int16). A nice SO reference: http://stackoverflow.com/questions/13351012/how-many-bytes-of-memory-does-each-type-in-net-consume-32-bit-environment

    • 7
  • Yogesh Sevankar
    Oct, 2019 18

    Int store number and character store values

    • 0
  • vineel vatsav
    Sep, 2015 6

    It depends on the processor. It can be two bytes or four bytes.

    • 0
  • Ajeet Mishra
    Sep, 2015 3

    I know it's equal to sizeof(int). The size of an int is really compiler dependent. Back in the day, when processors were 16 bit, an int was 2 bytes. Nowadays, it's most often 4 bytes on a 32 bits system or 8 bytes on 64 bits system.

    • 0
  • Srinivas Pabballa
    Aug, 2015 28

    i think ur question is wrong mr shamse alam. integer size is: 4bytes and char size is only 2bytes in c# .net. their is no point in ur question saying int is 2 byte and char is 4 byte.. ur absolutely wrong...

    • 0
  • Pankaj  Kumar Choudhary
    Jul, 2015 2

    https://msdn.microsoft.com/en-us/library/x9h8tsay.aspx

    • 0
  • Bir Singh
    Jul, 2015 2

    BECAUSE INT -NUMERICAL TYPE VALUE AND CHAR- CHARECTER TYPE VALUE

    • 0
  • Sethupalniyappan Subramanian
    Jun, 2015 29

    int takes 16 bit memory,so it take two byte.Actually char take one byte.In your case you may declare char[4] so it takes four byte.Generally character take 1 byte

    • 0
  • Sujeet Suman
    Jun, 2015 26

    https://msdn.microsoft.com/en-us/library/x9h8tsay.aspx

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS