 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Zero Initialization in C++
Zero initialization is setting the initial value of an object in c++ to zero.
Syntax
T{} ; char array [n] = “”; The situations in which zero initialization are performed are −
- Named variable with static or thread-local storage is initialized to zero. 
- It is used as initialization of values for non-class types and members of a class that do not have a constructor. 
- It is used to initialize a character array when its length is greater than the number of characters that are to be assigned. 
Points to remember
- Some types of variables like static variables and thread-local variables are first initialized to zero then reinitialized to a value when called. 
- A zero-initialized pointer is called a null pointer. 
Example
Program to show the implementation of zero initialization in C++ −
#include <iostream> #include <string> using namespace std; struct zeroInitialization {    int x, y, z; }; float f[3]; int* p; string s; int main(int argc, char* argv[]){    zeroInitialization obj = zeroInitialization();    cout<<"Zero initialized object variable :\t";    cout<<obj.x<<"\t"<<obj.y<<"\t"<<obj.z<<"\n";    cout<<"Zero initialized float value :\t";    cout<<f[0]<<"\t"<<f[1]<<"\t"<<f[2]<<"\n";    cout<<"Zero initialized pointer value :\t";    cout<<p<<"\n";    return 0; }  Output
Zero initialized object variable : 0 0 0 Zero initialized float value : 0 0 0 Zero initialized pointer value : 0
Advertisements
 