Initialising variable during compilation

I

invincible

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
 
K

Karl Heinz Buchegger

invincible said:
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;
}
 
A

Andre Caldas

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.
 
K

Karl Heinz Buchegger

Andre said:
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 :)
 
A

Andre Caldas

Hello!
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top