Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. What does mean "struct foo f = {0};"?

What does mean "struct foo f = {0};"?

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ant damage
    wrote on last edited by
    #1

    struct foo
    {
    int i;
    };

    foo f = {0}; // <- What does this mean?

    M R _ 3 Replies Last reply
    0
    • A ant damage

      struct foo
      {
      int i;
      };

      foo f = {0}; // <- What does this mean?

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      what about initialize the struct ?

      Watched code never compiles.

      1 Reply Last reply
      0
      • A ant damage

        struct foo
        {
        int i;
        };

        foo f = {0}; // <- What does this mean?

        R Offline
        R Offline
        rp_suman
        wrote on last edited by
        #3

        ant-damage wrote:

        foo f = {0}; // <- What does this mean?

        creating an instance of structure foo(in the name of "f") with i's value zero.

        -- "Programming is an art that fights back!"

        A 1 Reply Last reply
        0
        • A ant damage

          struct foo
          {
          int i;
          };

          foo f = {0}; // <- What does this mean?

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          In Visual Studio this will initialize the structure to all zeros similar to ZeroMemory(&f, sizof(struct foo));

          «_Superman_»
          I love work. It gives me something to do between weekends.

          Microsoft MVP (Visual C++)

          Polymorphism in C

          E 1 Reply Last reply
          0
          • R rp_suman

            ant-damage wrote:

            foo f = {0}; // <- What does this mean?

            creating an instance of structure foo(in the name of "f") with i's value zero.

            -- "Programming is an art that fights back!"

            A Offline
            A Offline
            ant damage
            wrote on last edited by
            #5

            And if we have

            struct point
            {
            float x;
            float y;
            float z;
            };

            struct face
            {
            point a;
            point b;
            point c;
            };

            face f = {0}; // <- This will initialize to zero the struct, and its elements?

            R 1 Reply Last reply
            0
            • A ant damage

              And if we have

              struct point
              {
              float x;
              float y;
              float z;
              };

              struct face
              {
              point a;
              point b;
              point c;
              };

              face f = {0}; // <- This will initialize to zero the struct, and its elements?

              R Offline
              R Offline
              rp_suman
              wrote on last edited by
              #6

              ant-damage wrote:

              struct face{ point a; point b; point c;};face f = {0}; // <- This will initialize to zero the struct, and its elements?

              Yes, (I guess point is of type similar to CPoint containing x & y), above code will initialize x & y values of a, b & c to zeroes.

              -- "Programming is an art that fights back!"

              A 1 Reply Last reply
              0
              • R rp_suman

                ant-damage wrote:

                struct face{ point a; point b; point c;};face f = {0}; // <- This will initialize to zero the struct, and its elements?

                Yes, (I guess point is of type similar to CPoint containing x & y), above code will initialize x & y values of a, b & c to zeroes.

                -- "Programming is an art that fights back!"

                A Offline
                A Offline
                ant damage
                wrote on last edited by
                #7

                That is exactly what I wanted to know. Thanks.

                R 1 Reply Last reply
                0
                • A ant damage

                  That is exactly what I wanted to know. Thanks.

                  R Offline
                  R Offline
                  rp_suman
                  wrote on last edited by
                  #8

                  You are welcome!! BTW: You can have constructors for initializing structures.

                  -- "Programming is an art that fights back!"

                  1 Reply Last reply
                  0
                  • _ _Superman_

                    In Visual Studio this will initialize the structure to all zeros similar to ZeroMemory(&f, sizof(struct foo));

                    «_Superman_»
                    I love work. It gives me something to do between weekends.

                    Microsoft MVP (Visual C++)

                    Polymorphism in C

                    E Offline
                    E Offline
                    Eugen Podsypalnikov
                    wrote on last edited by
                    #9

                    ... the code of ... = {0}; may be much faster (than the code of ZeroMemory(..)) :)

                    virtual void BeHappy() = 0;

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups