By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

Initialising variable during compilation

P: n/a
hi,

Problem:

i want to initialise local varibles variables during compilation

Question

1. Is there any flags to be set during compilation
2. By some possible ways

main.cpp

int main()
{
int i;
cout << i;
return 0;
}

When I run my program I should get value 0 always. Is this possible

Mohan
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
invincible wrote:

hi,

Problem:

i want to initialise local varibles variables during compilation

Question

1. Is there any flags to be set during compilation
2. By some possible ways

main.cpp

int main()
{
int i;
cout << i;
return 0;
}

When I run my program I should get value 0 always. Is this possible


You need a beginners book.

int main()
{
int i = 0;
cout << i;
return 0;
}

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #2

P: n/a
> You need a beginners book.

int main()
{
int i = 0;
cout << i;
return 0;
}


The guy wants to "not initialize" the variables, plus he wants to get
them initialized to zero when he does not explicitly initializes them.
(I am not saying one should do or not this!)

So the question is: "Is there a way to do that?".

There are many answers. For example:

1. This is off-topic!!

2. You shouldn't do this. This is not good practice.

3. There probably is a switch on your compiler to do it. This newsgroup
is not for compiler-specific questions.
Jul 23 '05 #3

P: n/a
Andre Caldas wrote:
You need a beginners book.

int main()
{
int i = 0;
cout << i;
return 0;
}


The guy wants to "not initialize" the variables, plus he wants to get
them initialized to zero when he does not explicitly initializes them.
(I am not saying one should do or not this!)

So the question is: "Is there a way to do that?".

There are many answers. For example:

1. This is off-topic!!

2. You shouldn't do this. This is not good practice.

3. There probably is a switch on your compiler to do it. This newsgroup
is not for compiler-specific questions.


or

4. Do it the right way as specified in the language. This way you don't need
1., 2. and 3. any longer :-)

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #4

P: n/a
Hello!

Karl Heinz Buchegger wrote:
There are many answers. For example:

1. This is off-topic!!

2. You shouldn't do this. This is not good practice.

3. There probably is a switch on your compiler to do it. This newsgroup
is not for compiler-specific questions.

or

4. Do it the right way as specified in the language. This way you don't need
1., 2. and 3. any longer :-)


Well, I guess yours (number 4) was in fact almost the same as 2. But I
was worried the guy didn't quite understand that you
_did_infact_understand_what_h_ wanted_.
He probably just thought: "No, that's not what I want. This guy thinks I
don't know how to write 'int i=0;'!!"

Andre Caldas.
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.