i want to know the differnce between int a=10 &
int a;
a=10;
though both look same and assign the value 10 to the variable a.
but in memory theres a big difference between te two.
Can anyone help me with this??
Sahilsikka
0
Newbie Poster
Recommended Answers
Jump to PostAFAIK
int a = 10;
will allow the compiler to directly constructa
with the value of 10 where as when you split it up the code still has to createa
and then you have an additional assignment to assign10
to it.
Jump to PostThere is no difference in behavior between the two. Both declare a variable "a" and give it the value 10.
Jump to PostIn a compiler without signifigant optimizations,
int a; a = 10;
might take extra intructions. Even in optimized compilers, if you haveint a; <code block>; a = 10;
it might not pick up on the fact that a was not modified until you assign it a value depending on …
All 9 Replies
NathanOliver
429
Veteran Poster
Featured Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
Hiroshe
499
Posting Whiz in Training
sepp2k
378
Practically a Master Poster
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
dinad578
9
Newbie Poster
sepp2k
378
Practically a Master Poster
cheryllocascio
0
Newbie Poster
DonnSchwartz
0
Newbie Poster
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.