Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of int(0) in int *pi = new int(0);?

Tags:

c++

int *pi = new int(0); 

What's the significance of 0 here? Does it mean integer array of length 0?

like image 992
understack Avatar asked Jun 16 '10 18:06

understack


2 Answers

It is an initializer (constructor parameter). The newly created int will have value of 0.

like image 198
Amardeep AC9MF Avatar answered Oct 04 '22 07:10

Amardeep AC9MF


It means you want a pointer to an int, and for the value of that int to be 0.

I once lost far too long on a bug that turned out to be someone wrote new char(10) when they meant new char[10]. Compiler was fine with it but it caused major corruption problems, which are so hard to spot. This was 10+ years ago and we didn't have the tools we do now. Will never forget it.

like image 27
Kate Gregory Avatar answered Oct 04 '22 08:10

Kate Gregory