Questions on short and pointer member variable

D

D. Susman

Hi,

1) When I define a variable like "short var", is it by default signed
or unsigned?
2) Say I have a class storing a pointer member variable. Is the
pointer assigned to 0 upon initialization of a class object
automatically or am I supposed to do it myself in the via
initialization list?

Thanks.
 
I

Ian Collins

D. Susman said:
Hi,

1) When I define a variable like "short var", is it by default signed
or unsigned?
Signed.

2) Say I have a class storing a pointer member variable. Is the
pointer assigned to 0 upon initialization of a class object
automatically or am I supposed to do it myself in the via
initialization list?
You have to initialise it.
 
K

Kai-Uwe Bux

D. Susman said:
Hi,

1) When I define a variable like "short var", is it by default signed
or unsigned?

"short var" will declare a variable of type short int, which is signed. See
[7.1.5.2] and Table 7 for details.

2) Say I have a class storing a pointer member variable. Is the
pointer assigned to 0 upon initialization of a class object
automatically or am I supposed to do it myself in the via
initialization list?

Members that are not of class type (e.g., pointers, arithmetic types, enums)
have indeterminate initial value unless you initialize them explicitly. See
[8/9] for details.


Best

Kai-Uwe Bux
 
M

Micah Cowan

D. Susman said:
Hi,

1) When I define a variable like "short var", is it by default signed
or unsigned?

For all of the standard integer types except for char, not specifying
signed or unsigned gives exactly the same semantics as if you had
specified "signed".

(char is a distinct type from either signed char or unsigned char, but
is required to have the same representation and set of values as one
of those.)
2) Say I have a class storing a pointer member variable. Is the
pointer assigned to 0 upon initialization of a class object
automatically or am I supposed to do it myself in the via
initialization list?

You need to do it explicitly; it won't be automatically initialized.
 
R

Ron Natalie

D. Susman said:
Hi,

1) When I define a variable like "short var", is it by default signed
or unsigned?

The absence of the word signed or unsigned implies signed for all types
except char. There are three distinct char types, char, unsigned char,
signed char. The char type is implementation defined as either signed
or unsigned but is a distinct type.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top