What is difference between initialization and assignment?




Answers were Sorted based on User's Feedback



What is difference between initialization and assignment?..

Answer / janet

Assignment can be done as many times as desired where as
initialization can be done only once.

Is This Answer Correct ?    156 Yes 24 No

What is difference between initialization and assignment?..

Answer / jaroosh

Those answers are actually highly insufficient.
Here are some differences to point that come to my mind :
a) you CANT assign to a const variable, whereas you CAN
initialize it. For example :
const AXC d = 3; //OK! initialization
d = 3; //WRONG! cannot assign to const
b) initialization IS about creating object
assignment IS about setting some value to object
This is why in the following code :
AXC d = 3;
AXC x;
x = 2;
first line will require an appropriate constructor:
AXC(int i) { ... }
whereas the third line will use overloaded assignment "="
operator if its specified (if not, it will use constructor
like above):
AXC operator =(int x) { ... }
c) Initialization also calls copy constructors, while
assignment does not :
A c;
A d = c; //Calls copy constructor of A
A e;
e = c; //Calls assignment operator of A

Is This Answer Correct ?    71 Yes 5 No

What is difference between initialization and assignment?..

Answer / zuber

Initialization can be can be done at the time of
declaration where as assiginment can be done anywhere

Is This Answer Correct ?    53 Yes 11 No




What is difference between initialization and assignment?..

Answer / hariharan,k

initialization mean's to initilise a variable.
assignment mean's assign value to a variable.

Is This Answer Correct ?    73 Yes 40 No

What is difference between initialization and assignment?..

Answer / suraj

Initialization is a type of assignment done at declaration
level, but assinment can be done anywhere.

Is This Answer Correct ?    23 Yes 4 No

What is difference between initialization and assignment?..

Answer / lucky

Some defference between Initialization and assignment
Initialization means whenever we initialize any var. at
declaration time.So as we initialize var. in init() in java
programming.For i.e.
prblic init()
{
int a=10;
}
Assignment means whenever we assigne any value in any var.
except const. variable.For i.e.
int a,b;
a=15; //right
b=a; //right
const c;
c=10 or c=a; //Worng
const d=20; //that is initialization

Is This Answer Correct ?    22 Yes 6 No

What is difference between initialization and assignment?..

Answer / njk

455

Is This Answer Correct ?    5 Yes 1 No

What is difference between initialization and assignment?..

Answer / sandeep mannarakkal

All object creation involves two steps,
1) Memory allocation
2) Memory initialization , so initialization is a part of object creation itself.
Assignment is the process of assigning values in to already available object.
Hope the concept is clear

Is This Answer Correct ?    3 Yes 0 No

What is difference between initialization and assignment?..

Answer / sweety

Initialization does the memory allocation, i.e. it assigns
the emory to the variable whereas assignment assigns a
value to the variable.

Is This Answer Correct ?    15 Yes 15 No

What is difference between initialization and assignment?..

Answer / adeolu

initialization is the first assignment value given to a
variable while assignment is the subsequent value giving to
the program variable

Is This Answer Correct ?    2 Yes 7 No

Post New Answer



More C++ General Interview Questions

class Foo { const int x; protected: Foo(int f); ~Foo(); }; Foo f; Referring to the sample code above, why will the class declaration not compile? a) The variable x is const. b) The destructor is protected. c) The destructor is not public. d) The constructor is protected. e) There is no default constructor.

5 Answers   Quark,


Difference between static global and global?

16 Answers   Microsoft, Wipro, Symphony,


If there are 1 to 100 Numbers in array of 101 elements. Which is the easy way to find repeated number?

2 Answers   Persistent,


Give a very good method to count the number of ones in a "n" (e.g. 32) bit number.

3 Answers  


What is "strstream" ?

1 Answers   Huawei,






what are the iterator and generic algorithms.

0 Answers  


Is there any difference between dlearations int* x and int *x? If so tell me the difference?

16 Answers   Lason,


1. What does the following do: void afunction(int *x) { x=new int; *x=12; } int main() { int v=10; afunction(&v); cout<<v; } a) Outputs 12 b) Outputs 10 c) Outputs the address of v

5 Answers   Quark,


Inline parameters : What does the compiler do with the parameters of inline function, that can be evaluated in runtime ?

0 Answers  


How many types of casting are there in C++? When is a dynamic cast,static_cast,reinterpret cast used?

2 Answers   CTS,


How the memory management in vectors are being done. What happens when the heap memory is full, and how do you handle it ?

0 Answers   Yahoo,


what is the emaning of '#include" "'?

5 Answers  






Categories