Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Application Security Testing: An Integral Part of DevOps

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.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date