C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
iOS
Java
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
8
Reply
int is 2 byte and char 4 byte why?
MD SHAMSE ALAM
10y
3.2k
0
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
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
Jason Wilczak
10y
7
It depends on the processor. It can be two bytes or four bytes.
vineel vatsav
10y
0
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.
Ajeet Mishra
10y
0
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...
Srinivas Pabballa
10y
0
https://msdn.microsoft.com/en-us/library/x9h8tsay.aspx
Pankaj Kumar Choudhary
10y
0
BECAUSE INT -NUMERICAL TYPE VALUE AND CHAR- CHARECTER TYPE VALUE
Bir Singh
10y
0
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
Sethupalniyappan Subramanian
10y
0
https://msdn.microsoft.com/en-us/library/x9h8tsay.aspx
Sujeet Suman
10y
0
Message