Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Re: A question ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 11 Topic 4120 of 4306
Post > Topic >>

Re: A question about structures

by Richard Heathfield <rjh@[EMAIL PROTECTED] > Apr 19, 2008 at 10:10 PM

Pat said:

<snip>
 
> But to clarify a comment you made, if I have a structure, say:
> 
> struct coordinateDefinition
> {
> float x;
> float y;
> float z;
> }
> 
> and use that to define the structure,
> 
> coordinateDefinition point1={1.5,2.3};
> 
> then by default, point1.z=0?

This is certainly true in C, because IF you initialise AT LEAST ONE of the

members of an aggregate object (e.g. a struct or an array), any that you 
don't initialise take on their default static initialisation values (0 for

integer types, NULL for pointers, 0.0 for doubles, and recursively for 
aggregates). Whether it's true in C++, I'm not certain.

> So you don't have to explicitly define all
> the members?

You don't have to explicitly *initialise* all the members, no.

> What if z were a char type instead?

<shrug> It would gain the value '\0' (i.e. a null character).

-- 
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www.
+rjh@[EMAIL PROTECTED]
 users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 




 11 Posts in Topic:
A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-19 11:06:19 
Re: A question about structures
Francis Glassborow <fr  2008-04-19 16:20:42 
Re: A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-19 17:13:44 
Re: A question about structures
Jensen Somers <jensen.  2008-04-19 23:25:38 
Re: A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-19 19:38:17 
Re: A question about structures
Barry Schwarz <schwarz  2008-04-19 10:55:40 
Re: A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-19 17:30:48 
Re: A question about structures
Richard Heathfield <rj  2008-04-19 22:10:45 
Re: A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-19 19:38:01 
Re: A question about structures
Jensen Somers <jensen.  2008-04-20 13:35:43 
Re: A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-20 11:09:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 12:58:29 CDT 2008.