Dave's Brain

Browse - Programming Tips - How can I initialize a struct to zero?

Date: 2014feb21
Language: C++

Q.  How can I initialize a struct to zero?

A.  Initialize the first member to zero and all the rest will
automatically be set to zero.  For example:

int a[10] = { 0 }; // Brace brackets
struct MyStruct mystruct = { 0 };
Very handy.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.