Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language:
Expertise: Beginner
May 8, 2002

A Quick Way To Initialize All the Members of a Struct To 0

 
// Quickly zero out a struct. This can be applied
// To an array of structs also, since
// memset() initializes memory regions

#include <string.h>

struct sample {
int a;
short int b;
int c;
};

struct sample s;

// Initialize all members to zero (Be careful of
// Incompatible Data types.
memset( s, 0, sizeof(sample) );

// Array of structs example
memset( s, 0, (sizeof(sample)*(<numelements>)) )
Jason Stewart
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date