binary operators

D

dogbert1793

Consider the code:

unsigned char uc;
cout << "sizeof( unsigned char ) = " << sizeof( uc ) << endl;
cout << "sizeof( ~unsigned char ) = " << sizeof( ~uc ) << endl;

Why is the output:

sizeof( unsigned char ) = 1
sizeof( ~unsigned char ) = 4

and not

sizeof( unsigned char ) = 1
sizeof( ~unsigned char ) = 1
 
B

Barry

Consider the code:

unsigned char uc;
cout << "sizeof( unsigned char ) = " << sizeof( uc ) << endl;
cout << "sizeof( ~unsigned char ) = " << sizeof( ~uc ) << endl;

Why is the output:

sizeof( unsigned char ) = 1
sizeof( ~unsigned char ) = 4

and not

sizeof( unsigned char ) = 1
sizeof( ~unsigned char ) = 1

[std--
4.5 Integral promotions [conv.prom]

3. An rvalue for an integral bit-field (9.6) can be converted to an
rvalue of type int if int can represent all
the values of the bit-field; otherwise, it can be converted to unsigned
int if unsigned int can represent
all the values of the bit-field. If the bit-field is larger yet, no
integral promotion applies to it. If the
bit-field has an enumerated type, it is treated as any other value of
that type for promotion purposes.
--End-std]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,047
Members
47,646
Latest member
xayaci5906

Latest Threads

Top