   structs initialization - simple doubt
  Hi, I just create a struct with have 2 pointers, I create an instance of that struct before main(), I want know if I have to care about "nulling" those pointers, since looks like this is automatic donne( but Im not sure)..How it works? C++ specification says all data created before main have to be "zeroed" ? This is donne before entering main() or just after?   
  It depends on what you mean by creating an instance of the struct before main(). If you mean that it's a global then it's guaranteed to be zero initialized.   ;  Types that don't have a default constructor (like "int") will not be initialized automatically, you'll have to do it manually.For convenience you could add a default constructor to your struct, that initializes its 2 pointer members.Edit: fixed typo   ;Quote:Original post by RattenhirnTypes that don't have a default constructor (like "int") will not be initialized automaticallyStatic objects are zero-initialized.int x; // initialized to 0int main(){    int y; // some random garbage value};  Thanks for the infoQuote:It depends on what you mean by creating an instance of the struct before main(). If you mean that it's a global then it's guaranteed to be zero initialized.Yes, a global.;  If the struct is not a global variable, though, you can easily zero initialize the whole thing like this:mystruct s = {0};   ;  Free English mini-lesson: you have a 'question', not a 'doubt'. (That was the best reference I could find with a quick search - if I find anything better, I'll replace it.)   ;Quote:Original post by direwulfIf the struct is not a global variable, though, you can easily zero initialize the whole thing like this:mystruct s = {0};You don't even need the zero. Just mystruct s = {}; will do.{ 0 } just says initialize the first member to zero and all the other members to their default values. {} just says initialize all members to their default values.   ;Quote:Original post by ZahlmanFree English mini-lesson: you have a 'question', not a 'doubt'. (That was the best reference I could find with a quick search - if I find anything better, I'll replace it.)Yes, it seems the OP was using a direct translation of "dúvida" as "doubt", which doesn't quite work.