difference between assignement and initialisation

S

sushant

hi all,

whats the difference between assignement and initialisation in C.
is assignement related with scanf() and initialisation with (int x=10;)

sushant
 
S

Shan

whats the difference between assignement and initialisation in C.

Initialisation is, you give a value during the creation of the
variable, like this:
int i = 10;

Assignment is that you give the variable some value after it got
created, like this:

int i; /*Creating the variable, but may have garbage value */
i = 10; /* Assigning 10 to the integer variable i*/
is assignement related with scanf() and initialisation with (int
x=10;)
To some extent yes, but may cover other scenarios too.

Cheers
Shan
 
M

Mike Wahler

sushant said:
hi all,

whats the difference between assignement and initialisation in C.

Initialization is the specifying of a value for an
object at the time you create it. Assignment is
the giving of a value to an already existing object.

int i = 10; /* define a type 'int' object, */
/* inititalized with value of 10 */

i = 25; /* assign a value to the already */
/* existing object 'i' */
is assignement related with scanf()

Not directly. However one of the operations 'scanf()'
can do is assign values to objects.
and initialisation with (int x=10;)

Yes, that's the correct syntax for initializing an object.

Which C book(s) are you reading?

-Mike
 
T

Taran

Initialize: assign value to a variable as it is declared/crated.

Assignment: assign value to a variable. It doesn't matter in this case
whether the variable was already assigned any value or not.


scanf does assign values to variables and so does various other
operations.

Perfect this is intialization.


This is very basic questions in C. I'd rather you go thru your C book
again and again!

HTH.
Regards,
Taran
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top