int x; int y; int *ptr; is not initialization, right?











up vote
18
down vote

favorite
1












I'm reading 'C++ All-in-One for Dummies' by J. P. Mueller and J. Cogswell and stumbled onto this:



#include <iostream>
using namespace std;
int main()
{
int ExpensiveComputer;
int CheapComputer;
int *ptrToComp;
...



This code starts out by initializing all the goodies involved — two integers
and a pointer to an integer.




Just to confirm, this is a mistake and should read '... by declaring', right? It's just strange to me that such basic mistakes still make their way to books.










share|improve this question









New contributor




John Allison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 4




    Yes you declare those variables, and define them. What you don't do is initialize them.
    – Some programmer dude
    2 days ago








  • 4




    You are correct, and yes, unfortunately there are a lot of crappy books out there.
    – 500 - Internal Server Error
    2 days ago






  • 6




    If you choose a book for dummies, what do you expect?
    – molbdnilo
    2 days ago






  • 8




    @molbdnilo, a clear and easy-to-understand explanation that's factually correct, though. :) Writing 'for dummies' books does not justify factual mistakes.
    – John Allison
    2 days ago






  • 1




    Re: should read '... by declaring'" -- that's defining. These three statements create three variables. They are definitions. A definition is also a declaration, but a declaration is not a definition.
    – Pete Becker
    2 days ago















up vote
18
down vote

favorite
1












I'm reading 'C++ All-in-One for Dummies' by J. P. Mueller and J. Cogswell and stumbled onto this:



#include <iostream>
using namespace std;
int main()
{
int ExpensiveComputer;
int CheapComputer;
int *ptrToComp;
...



This code starts out by initializing all the goodies involved — two integers
and a pointer to an integer.




Just to confirm, this is a mistake and should read '... by declaring', right? It's just strange to me that such basic mistakes still make their way to books.










share|improve this question









New contributor




John Allison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 4




    Yes you declare those variables, and define them. What you don't do is initialize them.
    – Some programmer dude
    2 days ago








  • 4




    You are correct, and yes, unfortunately there are a lot of crappy books out there.
    – 500 - Internal Server Error
    2 days ago






  • 6




    If you choose a book for dummies, what do you expect?
    – molbdnilo
    2 days ago






  • 8




    @molbdnilo, a clear and easy-to-understand explanation that's factually correct, though. :) Writing 'for dummies' books does not justify factual mistakes.
    – John Allison
    2 days ago






  • 1




    Re: should read '... by declaring'" -- that's defining. These three statements create three variables. They are definitions. A definition is also a declaration, but a declaration is not a definition.
    – Pete Becker
    2 days ago













up vote
18
down vote

favorite
1









up vote
18
down vote

favorite
1






1





I'm reading 'C++ All-in-One for Dummies' by J. P. Mueller and J. Cogswell and stumbled onto this:



#include <iostream>
using namespace std;
int main()
{
int ExpensiveComputer;
int CheapComputer;
int *ptrToComp;
...



This code starts out by initializing all the goodies involved — two integers
and a pointer to an integer.




Just to confirm, this is a mistake and should read '... by declaring', right? It's just strange to me that such basic mistakes still make their way to books.










share|improve this question









New contributor




John Allison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I'm reading 'C++ All-in-One for Dummies' by J. P. Mueller and J. Cogswell and stumbled onto this:



#include <iostream>
using namespace std;
int main()
{
int ExpensiveComputer;
int CheapComputer;
int *ptrToComp;
...



This code starts out by initializing all the goodies involved — two integers
and a pointer to an integer.




Just to confirm, this is a mistake and should read '... by declaring', right? It's just strange to me that such basic mistakes still make their way to books.







c++ initialization language-lawyer declaration terminology






share|improve this question









New contributor




John Allison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




John Allison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago





















New contributor




John Allison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









John Allison

11211




11211




New contributor




John Allison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





John Allison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






John Allison is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 4




    Yes you declare those variables, and define them. What you don't do is initialize them.
    – Some programmer dude
    2 days ago








  • 4




    You are correct, and yes, unfortunately there are a lot of crappy books out there.
    – 500 - Internal Server Error
    2 days ago






  • 6




    If you choose a book for dummies, what do you expect?
    – molbdnilo
    2 days ago






  • 8




    @molbdnilo, a clear and easy-to-understand explanation that's factually correct, though. :) Writing 'for dummies' books does not justify factual mistakes.
    – John Allison
    2 days ago






  • 1




    Re: should read '... by declaring'" -- that's defining. These three statements create three variables. They are definitions. A definition is also a declaration, but a declaration is not a definition.
    – Pete Becker
    2 days ago














  • 4




    Yes you declare those variables, and define them. What you don't do is initialize them.
    – Some programmer dude
    2 days ago








  • 4




    You are correct, and yes, unfortunately there are a lot of crappy books out there.
    – 500 - Internal Server Error
    2 days ago






  • 6




    If you choose a book for dummies, what do you expect?
    – molbdnilo
    2 days ago






  • 8




    @molbdnilo, a clear and easy-to-understand explanation that's factually correct, though. :) Writing 'for dummies' books does not justify factual mistakes.
    – John Allison
    2 days ago






  • 1




    Re: should read '... by declaring'" -- that's defining. These three statements create three variables. They are definitions. A definition is also a declaration, but a declaration is not a definition.
    – Pete Becker
    2 days ago








4




4




Yes you declare those variables, and define them. What you don't do is initialize them.
– Some programmer dude
2 days ago






Yes you declare those variables, and define them. What you don't do is initialize them.
– Some programmer dude
2 days ago






4




4




You are correct, and yes, unfortunately there are a lot of crappy books out there.
– 500 - Internal Server Error
2 days ago




You are correct, and yes, unfortunately there are a lot of crappy books out there.
– 500 - Internal Server Error
2 days ago




6




6




If you choose a book for dummies, what do you expect?
– molbdnilo
2 days ago




If you choose a book for dummies, what do you expect?
– molbdnilo
2 days ago




8




8




@molbdnilo, a clear and easy-to-understand explanation that's factually correct, though. :) Writing 'for dummies' books does not justify factual mistakes.
– John Allison
2 days ago




@molbdnilo, a clear and easy-to-understand explanation that's factually correct, though. :) Writing 'for dummies' books does not justify factual mistakes.
– John Allison
2 days ago




1




1




Re: should read '... by declaring'" -- that's defining. These three statements create three variables. They are definitions. A definition is also a declaration, but a declaration is not a definition.
– Pete Becker
2 days ago




Re: should read '... by declaring'" -- that's defining. These three statements create three variables. They are definitions. A definition is also a declaration, but a declaration is not a definition.
– Pete Becker
2 days ago












4 Answers
4






active

oldest

votes

















up vote
22
down vote



accepted










From the point of view of the language, this is default initialization. The problem is, they are initialized to indeterminate values.




otherwise, nothing is done: the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.



Default initialization of non-class variables with automatic and dynamic storage duration produces objects with indeterminate values (static and thread-local objects get zero initialized)




Note that any attempt to read these indeterminate values leads to UB.



From the standard, [dcl.init]/7




To default-initialize an object of type T means:




  • If T is a (possibly cv-qualified) class type ([class]), constructors are considered. The applicable constructors are enumerated
    ([over.match.ctor]), and the best one for the initializer () is chosen
    through overload resolution ([over.match]). The constructor thus
    selected is called, with an empty argument list, to initialize the
    object.


  • If T is an array type, each element is default-initialized.


  • Otherwise, no initialization is performed.








share|improve this answer



















  • 1




    There is a crucial difference between initialized with an indeterminate value and not initializated: the former requires a memory store, the latter does not.
    – Maxim Egorushkin
    2 days ago












  • @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
    – songyuanyao
    2 days ago










  • Not sure which expression you refer to.
    – Maxim Egorushkin
    2 days ago










  • @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
    – songyuanyao
    2 days ago






  • 4




    @MaximEgorushkin -- that may be formally true, but you cannot write a conforming program that can tell whether a memory store occurred in these cases, so the as-if rule says that they're the same thing.
    – Pete Becker
    2 days ago


















up vote
6
down vote













Yes you are correct.



You declared and defined these variables, you did not initialize them!



PS: What is the difference between a definition and a declaration?






share|improve this answer



















  • 1




    stackoverflow.com/questions/1410563/… defines
    – Fantastic Mr Fox
    2 days ago












  • @FantasticMrFox, yes, I read that before posting my question. It was just weird to me that the authors, having such experience (for what it's worth), could write something that's so trivially wrong. Having read songyuanyao 's answer, it's not so trivial, though.
    – John Allison
    2 days ago












  • FantasticMrFox you are right, updated. @JohnAllison I am not sure, it they wanted to be so on point, they would say default initialize with garbage/random values. Saying initialize a variable and not doing so is so misleading and wrong. I see what extra information songyuanyao's answer brought to the table, but it's not a boolean one. Anyway, glad you found an answer that fits your thoughts.
    – gsamaras
    2 days ago


















up vote
3
down vote













This code both declares and defines three variables but does not initialize them (their values are said to be indeterminate).



A variable declaration only must include keyword extern.






share|improve this answer






























    up vote
    1
    down vote













    Right. Hence, "dummies". :)



    We can't even blame this on legacy; historically C programmers would declare* a variable and then "initialize" it later with its first assignment.



    But it was never the case that simply declaring a variable, without an initializer, were deemed to be "initializing" it.**



    So the wording is just wrong.



    * Technically we're talking about definitions, but when we say "declare a variable" we almost always mean defining declarations.



    ** Though objects with static storage duration do undergo their own zero-initialisation phase before anything else happens, so forgoing initialisation yourself is not a catastrophe in that case. Still, we cannot claim that we have initialised that object.






    share|improve this answer



















    • 2




      A variable declaration only must include keyword extern, otherwise it is a definition. The initializer is a separate concern.
      – Maxim Egorushkin
      2 days ago








    • 1




      @MaximEgorushkin Definitions are declarations too. But, sure, we can say "simply defining a thing" too and the lesson stays the same. Not really the key point, is it?
      – Lightness Races in Orbit
      2 days ago








    • 1




      In a declaration only you can write, for example, extern int a; (no array bounds), unlike in a definition. Confusing the two never helps.
      – Maxim Egorushkin
      2 days ago








    • 2




      But it was never the case that simply declaring a thing without an initializer were deemed "initializing" it. - Except when it is static or global.
      – Fantastic Mr Fox
      2 days ago






    • 2




      @MaximEgorushkin Way off-topic and why not? Why is it important to you? Why does gsamaras use a picture of an airplane as their profile picture?
      – Lightness Races in Orbit
      2 days ago











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    John Allison is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391694%2fint-x-int-y-int-ptr-is-not-initialization-right%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    22
    down vote



    accepted










    From the point of view of the language, this is default initialization. The problem is, they are initialized to indeterminate values.




    otherwise, nothing is done: the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.



    Default initialization of non-class variables with automatic and dynamic storage duration produces objects with indeterminate values (static and thread-local objects get zero initialized)




    Note that any attempt to read these indeterminate values leads to UB.



    From the standard, [dcl.init]/7




    To default-initialize an object of type T means:




    • If T is a (possibly cv-qualified) class type ([class]), constructors are considered. The applicable constructors are enumerated
      ([over.match.ctor]), and the best one for the initializer () is chosen
      through overload resolution ([over.match]). The constructor thus
      selected is called, with an empty argument list, to initialize the
      object.


    • If T is an array type, each element is default-initialized.


    • Otherwise, no initialization is performed.








    share|improve this answer



















    • 1




      There is a crucial difference between initialized with an indeterminate value and not initializated: the former requires a memory store, the latter does not.
      – Maxim Egorushkin
      2 days ago












    • @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
      – songyuanyao
      2 days ago










    • Not sure which expression you refer to.
      – Maxim Egorushkin
      2 days ago










    • @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
      – songyuanyao
      2 days ago






    • 4




      @MaximEgorushkin -- that may be formally true, but you cannot write a conforming program that can tell whether a memory store occurred in these cases, so the as-if rule says that they're the same thing.
      – Pete Becker
      2 days ago















    up vote
    22
    down vote



    accepted










    From the point of view of the language, this is default initialization. The problem is, they are initialized to indeterminate values.




    otherwise, nothing is done: the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.



    Default initialization of non-class variables with automatic and dynamic storage duration produces objects with indeterminate values (static and thread-local objects get zero initialized)




    Note that any attempt to read these indeterminate values leads to UB.



    From the standard, [dcl.init]/7




    To default-initialize an object of type T means:




    • If T is a (possibly cv-qualified) class type ([class]), constructors are considered. The applicable constructors are enumerated
      ([over.match.ctor]), and the best one for the initializer () is chosen
      through overload resolution ([over.match]). The constructor thus
      selected is called, with an empty argument list, to initialize the
      object.


    • If T is an array type, each element is default-initialized.


    • Otherwise, no initialization is performed.








    share|improve this answer



















    • 1




      There is a crucial difference between initialized with an indeterminate value and not initializated: the former requires a memory store, the latter does not.
      – Maxim Egorushkin
      2 days ago












    • @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
      – songyuanyao
      2 days ago










    • Not sure which expression you refer to.
      – Maxim Egorushkin
      2 days ago










    • @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
      – songyuanyao
      2 days ago






    • 4




      @MaximEgorushkin -- that may be formally true, but you cannot write a conforming program that can tell whether a memory store occurred in these cases, so the as-if rule says that they're the same thing.
      – Pete Becker
      2 days ago













    up vote
    22
    down vote



    accepted







    up vote
    22
    down vote



    accepted






    From the point of view of the language, this is default initialization. The problem is, they are initialized to indeterminate values.




    otherwise, nothing is done: the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.



    Default initialization of non-class variables with automatic and dynamic storage duration produces objects with indeterminate values (static and thread-local objects get zero initialized)




    Note that any attempt to read these indeterminate values leads to UB.



    From the standard, [dcl.init]/7




    To default-initialize an object of type T means:




    • If T is a (possibly cv-qualified) class type ([class]), constructors are considered. The applicable constructors are enumerated
      ([over.match.ctor]), and the best one for the initializer () is chosen
      through overload resolution ([over.match]). The constructor thus
      selected is called, with an empty argument list, to initialize the
      object.


    • If T is an array type, each element is default-initialized.


    • Otherwise, no initialization is performed.








    share|improve this answer














    From the point of view of the language, this is default initialization. The problem is, they are initialized to indeterminate values.




    otherwise, nothing is done: the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.



    Default initialization of non-class variables with automatic and dynamic storage duration produces objects with indeterminate values (static and thread-local objects get zero initialized)




    Note that any attempt to read these indeterminate values leads to UB.



    From the standard, [dcl.init]/7




    To default-initialize an object of type T means:




    • If T is a (possibly cv-qualified) class type ([class]), constructors are considered. The applicable constructors are enumerated
      ([over.match.ctor]), and the best one for the initializer () is chosen
      through overload resolution ([over.match]). The constructor thus
      selected is called, with an empty argument list, to initialize the
      object.


    • If T is an array type, each element is default-initialized.


    • Otherwise, no initialization is performed.









    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 2 days ago

























    answered 2 days ago









    songyuanyao

    88.4k11170232




    88.4k11170232








    • 1




      There is a crucial difference between initialized with an indeterminate value and not initializated: the former requires a memory store, the latter does not.
      – Maxim Egorushkin
      2 days ago












    • @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
      – songyuanyao
      2 days ago










    • Not sure which expression you refer to.
      – Maxim Egorushkin
      2 days ago










    • @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
      – songyuanyao
      2 days ago






    • 4




      @MaximEgorushkin -- that may be formally true, but you cannot write a conforming program that can tell whether a memory store occurred in these cases, so the as-if rule says that they're the same thing.
      – Pete Becker
      2 days ago














    • 1




      There is a crucial difference between initialized with an indeterminate value and not initializated: the former requires a memory store, the latter does not.
      – Maxim Egorushkin
      2 days ago












    • @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
      – songyuanyao
      2 days ago










    • Not sure which expression you refer to.
      – Maxim Egorushkin
      2 days ago










    • @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
      – songyuanyao
      2 days ago






    • 4




      @MaximEgorushkin -- that may be formally true, but you cannot write a conforming program that can tell whether a memory store occurred in these cases, so the as-if rule says that they're the same thing.
      – Pete Becker
      2 days ago








    1




    1




    There is a crucial difference between initialized with an indeterminate value and not initializated: the former requires a memory store, the latter does not.
    – Maxim Egorushkin
    2 days ago






    There is a crucial difference between initialized with an indeterminate value and not initializated: the former requires a memory store, the latter does not.
    – Maxim Egorushkin
    2 days ago














    @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
    – songyuanyao
    2 days ago




    @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
    – songyuanyao
    2 days ago












    Not sure which expression you refer to.
    – Maxim Egorushkin
    2 days ago




    Not sure which expression you refer to.
    – Maxim Egorushkin
    2 days ago












    @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
    – songyuanyao
    2 days ago




    @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
    – songyuanyao
    2 days ago




    4




    4




    @MaximEgorushkin -- that may be formally true, but you cannot write a conforming program that can tell whether a memory store occurred in these cases, so the as-if rule says that they're the same thing.
    – Pete Becker
    2 days ago




    @MaximEgorushkin -- that may be formally true, but you cannot write a conforming program that can tell whether a memory store occurred in these cases, so the as-if rule says that they're the same thing.
    – Pete Becker
    2 days ago












    up vote
    6
    down vote













    Yes you are correct.



    You declared and defined these variables, you did not initialize them!



    PS: What is the difference between a definition and a declaration?






    share|improve this answer



















    • 1




      stackoverflow.com/questions/1410563/… defines
      – Fantastic Mr Fox
      2 days ago












    • @FantasticMrFox, yes, I read that before posting my question. It was just weird to me that the authors, having such experience (for what it's worth), could write something that's so trivially wrong. Having read songyuanyao 's answer, it's not so trivial, though.
      – John Allison
      2 days ago












    • FantasticMrFox you are right, updated. @JohnAllison I am not sure, it they wanted to be so on point, they would say default initialize with garbage/random values. Saying initialize a variable and not doing so is so misleading and wrong. I see what extra information songyuanyao's answer brought to the table, but it's not a boolean one. Anyway, glad you found an answer that fits your thoughts.
      – gsamaras
      2 days ago















    up vote
    6
    down vote













    Yes you are correct.



    You declared and defined these variables, you did not initialize them!



    PS: What is the difference between a definition and a declaration?






    share|improve this answer



















    • 1




      stackoverflow.com/questions/1410563/… defines
      – Fantastic Mr Fox
      2 days ago












    • @FantasticMrFox, yes, I read that before posting my question. It was just weird to me that the authors, having such experience (for what it's worth), could write something that's so trivially wrong. Having read songyuanyao 's answer, it's not so trivial, though.
      – John Allison
      2 days ago












    • FantasticMrFox you are right, updated. @JohnAllison I am not sure, it they wanted to be so on point, they would say default initialize with garbage/random values. Saying initialize a variable and not doing so is so misleading and wrong. I see what extra information songyuanyao's answer brought to the table, but it's not a boolean one. Anyway, glad you found an answer that fits your thoughts.
      – gsamaras
      2 days ago













    up vote
    6
    down vote










    up vote
    6
    down vote









    Yes you are correct.



    You declared and defined these variables, you did not initialize them!



    PS: What is the difference between a definition and a declaration?






    share|improve this answer














    Yes you are correct.



    You declared and defined these variables, you did not initialize them!



    PS: What is the difference between a definition and a declaration?







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 2 days ago

























    answered 2 days ago









    gsamaras

    47.9k2394174




    47.9k2394174








    • 1




      stackoverflow.com/questions/1410563/… defines
      – Fantastic Mr Fox
      2 days ago












    • @FantasticMrFox, yes, I read that before posting my question. It was just weird to me that the authors, having such experience (for what it's worth), could write something that's so trivially wrong. Having read songyuanyao 's answer, it's not so trivial, though.
      – John Allison
      2 days ago












    • FantasticMrFox you are right, updated. @JohnAllison I am not sure, it they wanted to be so on point, they would say default initialize with garbage/random values. Saying initialize a variable and not doing so is so misleading and wrong. I see what extra information songyuanyao's answer brought to the table, but it's not a boolean one. Anyway, glad you found an answer that fits your thoughts.
      – gsamaras
      2 days ago














    • 1




      stackoverflow.com/questions/1410563/… defines
      – Fantastic Mr Fox
      2 days ago












    • @FantasticMrFox, yes, I read that before posting my question. It was just weird to me that the authors, having such experience (for what it's worth), could write something that's so trivially wrong. Having read songyuanyao 's answer, it's not so trivial, though.
      – John Allison
      2 days ago












    • FantasticMrFox you are right, updated. @JohnAllison I am not sure, it they wanted to be so on point, they would say default initialize with garbage/random values. Saying initialize a variable and not doing so is so misleading and wrong. I see what extra information songyuanyao's answer brought to the table, but it's not a boolean one. Anyway, glad you found an answer that fits your thoughts.
      – gsamaras
      2 days ago








    1




    1




    stackoverflow.com/questions/1410563/… defines
    – Fantastic Mr Fox
    2 days ago






    stackoverflow.com/questions/1410563/… defines
    – Fantastic Mr Fox
    2 days ago














    @FantasticMrFox, yes, I read that before posting my question. It was just weird to me that the authors, having such experience (for what it's worth), could write something that's so trivially wrong. Having read songyuanyao 's answer, it's not so trivial, though.
    – John Allison
    2 days ago






    @FantasticMrFox, yes, I read that before posting my question. It was just weird to me that the authors, having such experience (for what it's worth), could write something that's so trivially wrong. Having read songyuanyao 's answer, it's not so trivial, though.
    – John Allison
    2 days ago














    FantasticMrFox you are right, updated. @JohnAllison I am not sure, it they wanted to be so on point, they would say default initialize with garbage/random values. Saying initialize a variable and not doing so is so misleading and wrong. I see what extra information songyuanyao's answer brought to the table, but it's not a boolean one. Anyway, glad you found an answer that fits your thoughts.
    – gsamaras
    2 days ago




    FantasticMrFox you are right, updated. @JohnAllison I am not sure, it they wanted to be so on point, they would say default initialize with garbage/random values. Saying initialize a variable and not doing so is so misleading and wrong. I see what extra information songyuanyao's answer brought to the table, but it's not a boolean one. Anyway, glad you found an answer that fits your thoughts.
    – gsamaras
    2 days ago










    up vote
    3
    down vote













    This code both declares and defines three variables but does not initialize them (their values are said to be indeterminate).



    A variable declaration only must include keyword extern.






    share|improve this answer



























      up vote
      3
      down vote













      This code both declares and defines three variables but does not initialize them (their values are said to be indeterminate).



      A variable declaration only must include keyword extern.






      share|improve this answer

























        up vote
        3
        down vote










        up vote
        3
        down vote









        This code both declares and defines three variables but does not initialize them (their values are said to be indeterminate).



        A variable declaration only must include keyword extern.






        share|improve this answer














        This code both declares and defines three variables but does not initialize them (their values are said to be indeterminate).



        A variable declaration only must include keyword extern.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago

























        answered 2 days ago









        Maxim Egorushkin

        83.3k1198179




        83.3k1198179






















            up vote
            1
            down vote













            Right. Hence, "dummies". :)



            We can't even blame this on legacy; historically C programmers would declare* a variable and then "initialize" it later with its first assignment.



            But it was never the case that simply declaring a variable, without an initializer, were deemed to be "initializing" it.**



            So the wording is just wrong.



            * Technically we're talking about definitions, but when we say "declare a variable" we almost always mean defining declarations.



            ** Though objects with static storage duration do undergo their own zero-initialisation phase before anything else happens, so forgoing initialisation yourself is not a catastrophe in that case. Still, we cannot claim that we have initialised that object.






            share|improve this answer



















            • 2




              A variable declaration only must include keyword extern, otherwise it is a definition. The initializer is a separate concern.
              – Maxim Egorushkin
              2 days ago








            • 1




              @MaximEgorushkin Definitions are declarations too. But, sure, we can say "simply defining a thing" too and the lesson stays the same. Not really the key point, is it?
              – Lightness Races in Orbit
              2 days ago








            • 1




              In a declaration only you can write, for example, extern int a; (no array bounds), unlike in a definition. Confusing the two never helps.
              – Maxim Egorushkin
              2 days ago








            • 2




              But it was never the case that simply declaring a thing without an initializer were deemed "initializing" it. - Except when it is static or global.
              – Fantastic Mr Fox
              2 days ago






            • 2




              @MaximEgorushkin Way off-topic and why not? Why is it important to you? Why does gsamaras use a picture of an airplane as their profile picture?
              – Lightness Races in Orbit
              2 days ago















            up vote
            1
            down vote













            Right. Hence, "dummies". :)



            We can't even blame this on legacy; historically C programmers would declare* a variable and then "initialize" it later with its first assignment.



            But it was never the case that simply declaring a variable, without an initializer, were deemed to be "initializing" it.**



            So the wording is just wrong.



            * Technically we're talking about definitions, but when we say "declare a variable" we almost always mean defining declarations.



            ** Though objects with static storage duration do undergo their own zero-initialisation phase before anything else happens, so forgoing initialisation yourself is not a catastrophe in that case. Still, we cannot claim that we have initialised that object.






            share|improve this answer



















            • 2




              A variable declaration only must include keyword extern, otherwise it is a definition. The initializer is a separate concern.
              – Maxim Egorushkin
              2 days ago








            • 1




              @MaximEgorushkin Definitions are declarations too. But, sure, we can say "simply defining a thing" too and the lesson stays the same. Not really the key point, is it?
              – Lightness Races in Orbit
              2 days ago








            • 1




              In a declaration only you can write, for example, extern int a; (no array bounds), unlike in a definition. Confusing the two never helps.
              – Maxim Egorushkin
              2 days ago








            • 2




              But it was never the case that simply declaring a thing without an initializer were deemed "initializing" it. - Except when it is static or global.
              – Fantastic Mr Fox
              2 days ago






            • 2




              @MaximEgorushkin Way off-topic and why not? Why is it important to you? Why does gsamaras use a picture of an airplane as their profile picture?
              – Lightness Races in Orbit
              2 days ago













            up vote
            1
            down vote










            up vote
            1
            down vote









            Right. Hence, "dummies". :)



            We can't even blame this on legacy; historically C programmers would declare* a variable and then "initialize" it later with its first assignment.



            But it was never the case that simply declaring a variable, without an initializer, were deemed to be "initializing" it.**



            So the wording is just wrong.



            * Technically we're talking about definitions, but when we say "declare a variable" we almost always mean defining declarations.



            ** Though objects with static storage duration do undergo their own zero-initialisation phase before anything else happens, so forgoing initialisation yourself is not a catastrophe in that case. Still, we cannot claim that we have initialised that object.






            share|improve this answer














            Right. Hence, "dummies". :)



            We can't even blame this on legacy; historically C programmers would declare* a variable and then "initialize" it later with its first assignment.



            But it was never the case that simply declaring a variable, without an initializer, were deemed to be "initializing" it.**



            So the wording is just wrong.



            * Technically we're talking about definitions, but when we say "declare a variable" we almost always mean defining declarations.



            ** Though objects with static storage duration do undergo their own zero-initialisation phase before anything else happens, so forgoing initialisation yourself is not a catastrophe in that case. Still, we cannot claim that we have initialised that object.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 days ago

























            answered 2 days ago









            Lightness Races in Orbit

            278k51445763




            278k51445763








            • 2




              A variable declaration only must include keyword extern, otherwise it is a definition. The initializer is a separate concern.
              – Maxim Egorushkin
              2 days ago








            • 1




              @MaximEgorushkin Definitions are declarations too. But, sure, we can say "simply defining a thing" too and the lesson stays the same. Not really the key point, is it?
              – Lightness Races in Orbit
              2 days ago








            • 1




              In a declaration only you can write, for example, extern int a; (no array bounds), unlike in a definition. Confusing the two never helps.
              – Maxim Egorushkin
              2 days ago








            • 2




              But it was never the case that simply declaring a thing without an initializer were deemed "initializing" it. - Except when it is static or global.
              – Fantastic Mr Fox
              2 days ago






            • 2




              @MaximEgorushkin Way off-topic and why not? Why is it important to you? Why does gsamaras use a picture of an airplane as their profile picture?
              – Lightness Races in Orbit
              2 days ago














            • 2




              A variable declaration only must include keyword extern, otherwise it is a definition. The initializer is a separate concern.
              – Maxim Egorushkin
              2 days ago








            • 1




              @MaximEgorushkin Definitions are declarations too. But, sure, we can say "simply defining a thing" too and the lesson stays the same. Not really the key point, is it?
              – Lightness Races in Orbit
              2 days ago








            • 1




              In a declaration only you can write, for example, extern int a; (no array bounds), unlike in a definition. Confusing the two never helps.
              – Maxim Egorushkin
              2 days ago








            • 2




              But it was never the case that simply declaring a thing without an initializer were deemed "initializing" it. - Except when it is static or global.
              – Fantastic Mr Fox
              2 days ago






            • 2




              @MaximEgorushkin Way off-topic and why not? Why is it important to you? Why does gsamaras use a picture of an airplane as their profile picture?
              – Lightness Races in Orbit
              2 days ago








            2




            2




            A variable declaration only must include keyword extern, otherwise it is a definition. The initializer is a separate concern.
            – Maxim Egorushkin
            2 days ago






            A variable declaration only must include keyword extern, otherwise it is a definition. The initializer is a separate concern.
            – Maxim Egorushkin
            2 days ago






            1




            1




            @MaximEgorushkin Definitions are declarations too. But, sure, we can say "simply defining a thing" too and the lesson stays the same. Not really the key point, is it?
            – Lightness Races in Orbit
            2 days ago






            @MaximEgorushkin Definitions are declarations too. But, sure, we can say "simply defining a thing" too and the lesson stays the same. Not really the key point, is it?
            – Lightness Races in Orbit
            2 days ago






            1




            1




            In a declaration only you can write, for example, extern int a; (no array bounds), unlike in a definition. Confusing the two never helps.
            – Maxim Egorushkin
            2 days ago






            In a declaration only you can write, for example, extern int a; (no array bounds), unlike in a definition. Confusing the two never helps.
            – Maxim Egorushkin
            2 days ago






            2




            2




            But it was never the case that simply declaring a thing without an initializer were deemed "initializing" it. - Except when it is static or global.
            – Fantastic Mr Fox
            2 days ago




            But it was never the case that simply declaring a thing without an initializer were deemed "initializing" it. - Except when it is static or global.
            – Fantastic Mr Fox
            2 days ago




            2




            2




            @MaximEgorushkin Way off-topic and why not? Why is it important to you? Why does gsamaras use a picture of an airplane as their profile picture?
            – Lightness Races in Orbit
            2 days ago




            @MaximEgorushkin Way off-topic and why not? Why is it important to you? Why does gsamaras use a picture of an airplane as their profile picture?
            – Lightness Races in Orbit
            2 days ago










            John Allison is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            John Allison is a new contributor. Be nice, and check out our Code of Conduct.













            John Allison is a new contributor. Be nice, and check out our Code of Conduct.












            John Allison is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391694%2fint-x-int-y-int-ptr-is-not-initialization-right%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Quarter-circle Tiles

            build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

            Mont Emei