473,385 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

sizeof(char)

I have a C book that says the sizeof a char is one byte. Is this true for
C++?
Jul 22 '05 #1
5 16532
"nsgi_2004" <no****@nospam.com> wrote in message
news:X1xvc.42929$mm1.41139@fed1read06...
I have a C book that says the sizeof a char is one byte. Is this true for
C++?


Yes.
Jul 22 '05 #2
"nsgi_2004" <no****@nospam.com> wrote...
I have a C book that says the sizeof a char is one byte. Is this true for
C++?


sizeof(char) is always 1, yes. 'char' and 'byte' are synonyms in
both C and C++ when sizes are concerned.

V
Jul 22 '05 #3
On Wed, 2 Jun 2004 20:37:24 -0700 in comp.lang.c++, "nsgi_2004"
<no****@nospam.com> wrote,
I have a C book that says the sizeof a char is one byte. Is this true for
C++?


Yes. Note that a byte or char must be AT LEAST 8 bits in size,
but can be any number larger.

Jul 22 '05 #4
"nsgi_2004" <no****@nospam.com> wrote in message news:<X1xvc.42929$mm1.41139@fed1read06>...
I have a C book that says the sizeof a char is one byte. Is this true for
C++?


Yes, because C++ redefines byte to mean the size of a char. It's not
always the 8-bit thingy you might expect. This is shared between C
and C++, It's relevant e.g. for some DSP chips inside cellphones
that have 32 bits per byte. Now, those are programmed in C not C++,
but C++ felt no need to differ from C here. If anyone writes a
C++ compiler for such things, they can still use the same 32-bit
char.

Regards,
Michiel Salters
Jul 22 '05 #5
Michiel Salters wrote:
"nsgi_2004" <no****@nospam.com> wrote in message news:<X1xvc.42929$mm1.41139@fed1read06>...
I have a C book that says the sizeof a char is one byte. Is this true for
C++?

Yes, because C++ redefines byte to mean the size of a char. It's not
always the 8-bit thingy you might expect. This is shared between C
and C++, It's relevant e.g. for some DSP chips inside cellphones
that have 32 bits per byte. Now, those are programmed in C not C++,
but C++ felt no need to differ from C here. If anyone writes a
C++ compiler for such things, they can still use the same 32-bit
char.

Regards,
Michiel Salters


Yep. If you want to specify an 8-bit quantity, you might want to follow
the lead of the internet RFC guys and call it an "octet". sizeof(char)
is 1. Period. Regardless of the actual number of bits in it. Just for
reference, IIRC from my original K&R, one of the early C implementations
was on a machine with 9-bit "bytes".
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: José de Paula | last post by:
Is it a given that sizeof(char) always yields 1, no matter the implementation? I ask because I saw some critics against char * ptr = malloc (sizeof(char) * NUM); in favour of simply char * ptr...
9
by: M Welinder | last post by:
This doesn't work with any C compiler that I can find. They all report a syntax error: printf ("%d\n", (int)sizeof (char)(char)2); Now the question is "why?" "sizeof" and "(char)" have...
9
by: Sunner Sun | last post by:
Hi, all FAQ of comp.lang.c said "In C, type char is defined as occupying one byte, so it is usually 8 bits". (http://www.eskimo.com/~scs/cclass/notes/sx2a.html) But I found in C99 that "An...
12
by: Olaf \El Blanco\ | last post by:
How many bits we need to save the "number" 1 in a C text file? 00000001? 1 byte? And the "number" 12? Is also a byte? 00001100? And the "number" 300?
0
by: davidb | last post by:
Hi, does someone know how to get the length of a 2 dimensional string array: here what i need: ---------------------------------------------------------------- char **getList(void){ char...
1
by: svlsr2000 | last post by:
Here is a small program which i saw a couple of years ago. #include<stdio.h> int main() { char x; if(sizeof(int)==sizeof('a')) printf("\n C compiler\n"); ...
2
by: arnaudk | last post by:
Why is sizeof(char*) = 4? I would have expected 1... Is it because a pointer is stored as an int ?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.