Declaration and initialisation of variables

Hi all,

What is difference between,
int a=10;

and

int a;
a=10;

I have checked executing a sample code in assembly mode but i didn't find any difference. please comment on this.
for basic types like int, there's probably not going to be any difference.

For complex types like classes Foo a = bar; calls a ctor that takes 'bar' as a parameter.

Whereas Foo a; a = bar; calls the default ctor, then makes a seperate call to the assignment operator.



they both ultimately do two things for your program

1. it declares the data type that you may want to use in this case int.
2. the value 10 becomes assigned to your invented identifier in this case its a.


They are two options with the same outcome. The c like variable initialization ( int a=10;) is more often used when your declaring local variables.
Last edited on
+1 Disch
Topic archived. No new replies allowed.