ok, quick question for those who know the standard well. when is a variable (and array and class object) set to 0 by default (all elements, all members) in C++. i know that if it's global it should be (is it?). are there any other cases?

Recommended Answers

All 5 Replies

Member Avatar for iamthwee

I don't know the standard well at all. But I'd say it was always a good idea to intialise your variables, where ever they may be.

ok, quick question for those who know the standard well. when is a variable (and array and class object) set to 0 by default (all elements, all members) in C++. i know that if it's global it should be (is it?). are there any other cases?

static also,
well u can use sometimes like, but i never found it a gud idea.

int i[100] = {0} ;

intializer list in a class also help to achive it.

but i never found it a gud idea.

int i[100] = {0} ;

Why not?

Why not?

beacuse it does not works when int i[100] is a memeber of a class.
rest if it is not a member of a class performence wise it is a good thing to write it that way.

ok, thanks for the replies!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.