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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
18
down vote

favorite
2












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
    Nov 20 at 11:11







  • 4




    You are correct, and yes, unfortunately there are a lot of crappy books out there.
    – 500 - Internal Server Error
    Nov 20 at 11:11






  • 6




    If you choose a book for dummies, what do you expect?
    – molbdnilo
    Nov 20 at 11:17






  • 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
    Nov 20 at 11:31






  • 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
    Nov 20 at 15:35














up vote
18
down vote

favorite
2












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
    Nov 20 at 11:11







  • 4




    You are correct, and yes, unfortunately there are a lot of crappy books out there.
    – 500 - Internal Server Error
    Nov 20 at 11:11






  • 6




    If you choose a book for dummies, what do you expect?
    – molbdnilo
    Nov 20 at 11:17






  • 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
    Nov 20 at 11:31






  • 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
    Nov 20 at 15:35












up vote
18
down vote

favorite
2









up vote
18
down vote

favorite
2






2





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 Nov 20 at 11:56





















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 Nov 20 at 11:09









John Allison

12411




12411




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
    Nov 20 at 11:11







  • 4




    You are correct, and yes, unfortunately there are a lot of crappy books out there.
    – 500 - Internal Server Error
    Nov 20 at 11:11






  • 6




    If you choose a book for dummies, what do you expect?
    – molbdnilo
    Nov 20 at 11:17






  • 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
    Nov 20 at 11:31






  • 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
    Nov 20 at 15:35












  • 4




    Yes you declare those variables, and define them. What you don't do is initialize them.
    – Some programmer dude
    Nov 20 at 11:11







  • 4




    You are correct, and yes, unfortunately there are a lot of crappy books out there.
    – 500 - Internal Server Error
    Nov 20 at 11:11






  • 6




    If you choose a book for dummies, what do you expect?
    – molbdnilo
    Nov 20 at 11:17






  • 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
    Nov 20 at 11:31






  • 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
    Nov 20 at 15:35







4




4




Yes you declare those variables, and define them. What you don't do is initialize them.
– Some programmer dude
Nov 20 at 11:11





Yes you declare those variables, and define them. What you don't do is initialize them.
– Some programmer dude
Nov 20 at 11:11





4




4




You are correct, and yes, unfortunately there are a lot of crappy books out there.
– 500 - Internal Server Error
Nov 20 at 11:11




You are correct, and yes, unfortunately there are a lot of crappy books out there.
– 500 - Internal Server Error
Nov 20 at 11:11




6




6




If you choose a book for dummies, what do you expect?
– molbdnilo
Nov 20 at 11:17




If you choose a book for dummies, what do you expect?
– molbdnilo
Nov 20 at 11:17




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
Nov 20 at 11:31




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




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
Nov 20 at 15:35




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
Nov 20 at 15:35












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
    Nov 20 at 11:34











  • @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
    – songyuanyao
    Nov 20 at 11:39










  • Not sure which expression you refer to.
    – Maxim Egorushkin
    Nov 20 at 11:41










  • @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
    – songyuanyao
    Nov 20 at 11:42






  • 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
    Nov 20 at 15:33

















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
    Nov 20 at 11:19











  • @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
    Nov 20 at 11:25











  • 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
    Nov 20 at 14:29

















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
      Nov 20 at 11:47







    • 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
      Nov 20 at 11:53







    • 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
      Nov 20 at 12:10







    • 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
      Nov 20 at 14:01






    • 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
      Nov 20 at 14:35










    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
      Nov 20 at 11:34











    • @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
      – songyuanyao
      Nov 20 at 11:39










    • Not sure which expression you refer to.
      – Maxim Egorushkin
      Nov 20 at 11:41










    • @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
      – songyuanyao
      Nov 20 at 11:42






    • 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
      Nov 20 at 15:33














    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
      Nov 20 at 11:34











    • @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
      – songyuanyao
      Nov 20 at 11:39










    • Not sure which expression you refer to.
      – Maxim Egorushkin
      Nov 20 at 11:41










    • @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
      – songyuanyao
      Nov 20 at 11:42






    • 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
      Nov 20 at 15:33












    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 Nov 20 at 11:51

























    answered Nov 20 at 11:21









    songyuanyao

    88.5k11170232




    88.5k11170232







    • 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
      Nov 20 at 11:34











    • @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
      – songyuanyao
      Nov 20 at 11:39










    • Not sure which expression you refer to.
      – Maxim Egorushkin
      Nov 20 at 11:41










    • @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
      – songyuanyao
      Nov 20 at 11:42






    • 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
      Nov 20 at 15:33












    • 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
      Nov 20 at 11:34











    • @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
      – songyuanyao
      Nov 20 at 11:39










    • Not sure which expression you refer to.
      – Maxim Egorushkin
      Nov 20 at 11:41










    • @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
      – songyuanyao
      Nov 20 at 11:42






    • 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
      Nov 20 at 15:33







    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
    Nov 20 at 11:34





    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
    Nov 20 at 11:34













    @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
    – songyuanyao
    Nov 20 at 11:39




    @MaximEgorushkin That means the expression of cppreference.com is not accurate either..?
    – songyuanyao
    Nov 20 at 11:39












    Not sure which expression you refer to.
    – Maxim Egorushkin
    Nov 20 at 11:41




    Not sure which expression you refer to.
    – Maxim Egorushkin
    Nov 20 at 11:41












    @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
    – songyuanyao
    Nov 20 at 11:42




    @MaximEgorushkin the objects with automatic storage duration (and their subobjects) are initialized to indeterminate values.
    – songyuanyao
    Nov 20 at 11:42




    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
    Nov 20 at 15:33




    @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
    Nov 20 at 15:33












    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
      Nov 20 at 11:19











    • @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
      Nov 20 at 11:25











    • 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
      Nov 20 at 14:29














    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
      Nov 20 at 11:19











    • @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
      Nov 20 at 11:25











    • 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
      Nov 20 at 14:29












    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 Nov 20 at 13:18

























    answered Nov 20 at 11:13









    gsamaras

    48k2394174




    48k2394174







    • 1




      stackoverflow.com/questions/1410563/… defines
      – Fantastic Mr Fox
      Nov 20 at 11:19











    • @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
      Nov 20 at 11:25











    • 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
      Nov 20 at 14:29












    • 1




      stackoverflow.com/questions/1410563/… defines
      – Fantastic Mr Fox
      Nov 20 at 11:19











    • @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
      Nov 20 at 11:25











    • 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
      Nov 20 at 14:29







    1




    1




    stackoverflow.com/questions/1410563/… defines
    – Fantastic Mr Fox
    Nov 20 at 11:19





    stackoverflow.com/questions/1410563/… defines
    – Fantastic Mr Fox
    Nov 20 at 11:19













    @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
    Nov 20 at 11:25





    @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
    Nov 20 at 11:25













    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
    Nov 20 at 14:29




    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
    Nov 20 at 14:29










    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 Nov 20 at 11:32

























        answered Nov 20 at 11:18









        Maxim Egorushkin

        83.4k1198179




        83.4k1198179




















            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
              Nov 20 at 11:47







            • 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
              Nov 20 at 11:53







            • 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
              Nov 20 at 12:10







            • 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
              Nov 20 at 14:01






            • 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
              Nov 20 at 14:35














            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
              Nov 20 at 11:47







            • 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
              Nov 20 at 11:53







            • 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
              Nov 20 at 12:10







            • 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
              Nov 20 at 14:01






            • 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
              Nov 20 at 14:35












            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 Nov 20 at 14:15

























            answered Nov 20 at 11:46









            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
              Nov 20 at 11:47







            • 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
              Nov 20 at 11:53







            • 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
              Nov 20 at 12:10







            • 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
              Nov 20 at 14:01






            • 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
              Nov 20 at 14:35












            • 2




              A variable declaration only must include keyword extern, otherwise it is a definition. The initializer is a separate concern.
              – Maxim Egorushkin
              Nov 20 at 11:47







            • 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
              Nov 20 at 11:53







            • 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
              Nov 20 at 12:10







            • 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
              Nov 20 at 14:01






            • 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
              Nov 20 at 14:35







            2




            2




            A variable declaration only must include keyword extern, otherwise it is a definition. The initializer is a separate concern.
            – Maxim Egorushkin
            Nov 20 at 11:47





            A variable declaration only must include keyword extern, otherwise it is a definition. The initializer is a separate concern.
            – Maxim Egorushkin
            Nov 20 at 11:47





            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
            Nov 20 at 11:53





            @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
            Nov 20 at 11:53





            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
            Nov 20 at 12:10





            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
            Nov 20 at 12:10





            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
            Nov 20 at 14:01




            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
            Nov 20 at 14:01




            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
            Nov 20 at 14:35




            @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
            Nov 20 at 14:35










            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

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?