Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New - initialization

 
Lazaro Caruso
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I thought that when I use new "with round brackets", it zeroes matrix, but today I found something strange. Here is the code:


And here is my output:
0: 6956096
1: 6955792
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0
8: 0
9: 0

Why t[0] and t[1] aren't zeros? I am using Code Blocks 8.02
 
Anthony Aj Williams
author
Ranch Hand
Posts: 57
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lazaro Caruso wrote:
I thought that when I use new "with round brackets", it zeroes matrix,


That is supposed to be the case. An initializer of () should value-initialize the array, which value-initializes each element. For int objects, value-initialization means initialization with zero.

Lazaro Caruso wrote:Hi,Why t[0] and t[1] aren't zeros? I am using Code Blocks 8.02


I guess there's a bug in the compiler. I have known other compilers have bugs with regards to value-initialization of int objects.
 
Lazaro Caruso
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mhm so it's all about compiler. Thanks for reply.
 
Anand Hariharan
Rancher
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lazaro Caruso wrote:Mhm so it's all about compiler.


Code Blocks is an IDE that can be configured to use any compiler. Which compiler are you using?

Why don't you use a vector?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic