Some simple questions

I

Ioannis Vranos

1. 1U means that 1 is an unsigned int and not another unsigned type?

2. '\012' and '\xb' values are the same with 012 and 0xb?

3. Any numbers appearing like the following:

'\546'

are considered octals or decimals?
 
J

Juha Nieminen

Ioannis said:
1. 1U means that 1 is an unsigned int and not another unsigned type?

Unsigned int.
2. '\012' and '\xb' values are the same with 012 and 0xb?

No. The former are of type char, while the latter are of type int.
3. Any numbers appearing like the following:

'\546'

are considered octals or decimals?

I don't remember. Try google.
 
I

Ioannis Vranos

Juha said:
Unsigned int.

Is there any specifier of unsigned short?

No. The former are of type char, while the latter are of type int.


OK, apart from the type, are these the same values?

I don't remember. Try google.

If anyone has a specific answer it will be better. As for trying, a
compiler is better than google for this case I guess. :)
 
I

Ioannis Vranos

Ioannis said:
Is there any specifier of unsigned short?




OK, apart from the type, are these the same values?



If anyone has a specific answer it will be better. As for trying, a
compiler is better than google for this case I guess. :)


The code:

#include <iostream>


int main()
{
using namespace std;

int x= '\146';


cout<< x<< "\n"<< oct<< x<< "\n"<< hex<< x<< endl;
}


produces in my system:


[john@localhost src]$ ./foobar-cpp
102
146
66
[john@localhost src]$


Can't reach a conclusion.
 
I

Ioannis Vranos

Ioannis said:
Ioannis said:
Is there any specifier of unsigned short?




OK, apart from the type, are these the same values?



If anyone has a specific answer it will be better. As for trying, a
compiler is better than google for this case I guess. :)


The code:

#include <iostream>


int main()
{
using namespace std;

int x= '\146';


cout<< x<< "\n"<< oct<< x<< "\n"<< hex<< x<< endl;
}


produces in my system:


[john@localhost src]$ ./foobar-cpp
102
146
66
[john@localhost src]$


Can't reach a conclusion.


Ehm, actually it looks like it is octal.
 
J

James Kanze

1. 1U means that 1 is an unsigned int and not another unsigned type?

Yes, but only because 1 is guaranteed to fit in an int. If
integer literal which is suffixed by u or U, "its type is the
first of these types in which its value can be represented:
unsigned int, unsigned long int." C++0x will add long long, and
provisions for extended integral types (but U or u will always
guarantee an unsigned type, I think).
2. '\012' and '\xb' values are the same with 012 and 0xb?

No. The first two have type char, the last two type int. (They
have the same numeric value of course, but I'm sure you knew
that.)
3. Any numbers appearing like the following:

are considered octals or decimals?

Octals. Character escape sequences only exist for octal and
hexadecimal, not for decimal. (Similarly, the length and
precision fields in a printf format specifier are always
decimal, regardless of the format; e.g. "%.017f" and "%.17f"
specify exactly the same format, and in "%010d", the initial 0
is a flag, saying to use 0 as a fill character, and not space,
and does not mean that the width is octal.)
 
I

Ioannis Vranos

James said:
Yes, but only because 1 is guaranteed to fit in an int. If
integer literal which is suffixed by u or U, "its type is the
first of these types in which its value can be represented:
unsigned int, unsigned long int."


Thanks for the info.

C++0x will add long long, and
provisions for extended integral types (but U or u will always
guarantee an unsigned type, I think).


I will bother for C++0x when it is ratified and is widely implemented,
that is about 4 years after it is finished at least. :)

No. The first two have type char, the last two type int. (They
have the same numeric value of course, but I'm sure you knew
that.)


Actually I knew the first but was not sure for the second. :)


Octals. Character escape sequences only exist for octal and
hexadecimal, not for decimal.


I suppose you mean numeric escape sequences, and not talking about '\n',
'\t' etc.
 
J

James Kanze

James Kanze wrote:

[...]
I will bother for C++0x when it is ratified and is widely
implemented, that is about 4 years after it is finished at
least. :)

Were it only so. In practice, some features are already widely
implemented (such as long long), others probably never will be
(how many compilers support export, from C++98).

[...]
I suppose you mean numeric escape sequences, and not talking
about '\n', '\t' etc.

Yes. Things like '\t' are neither octal nor decimal, of course.
 
M

Micah Cowan

Juha Nieminen said:
Unsigned int.


No. The former are of type char, while the latter are of type int.

(Note that this differs from C, where all of the above are of type
int.)
 
J

Juha Nieminen

Victor said:
No, Micah meant all literals in '2' are of type 'int' in C. There
are no literals of type 'char' in C.

My answer was a rather subtle hint which tried to say "please quote
only the relevant parts of what you are answering to, to avoid confusion".
 
V

Victor Bazarov

Juha said:
My answer was a rather subtle hint which tried to say "please quote
only the relevant parts of what you are answering to, to avoid
confusion".

'Twas too subtle for me, obviously.

V
 

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
473,777
Messages
2,569,604
Members
45,219
Latest member
KristieKoh

Latest Threads

Top