difference between assignement and initialisation

Discussion in 'C Programming' started by sushant, Jan 4, 2005.

  1. sushant

    sushant Guest

    hi all,

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

    sushant
     
    sushant, Jan 4, 2005
    #1
    1. Advertising

  2. sushant

    Shan Guest

    >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
     
    Shan, Jan 4, 2005
    #2
    1. Advertising

  3. sushant

    Mike Wahler Guest

    "sushant" <> wrote in message
    news:...
    > 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
     
    Mike Wahler, Jan 5, 2005
    #3
  4. sushant

    Taran Guest

    > "sushant" <> wrote in message
    > news:...
    > > hi all,
    > >
    > > whats the difference between assignement and initialisation in C.


    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.


    > > is assignement related with scanf()


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

    > >and initialisation with (int x=10;)


    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
     
    Taran, Jan 5, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    0
    Views:
    295
    Ken Varn
    May 4, 2004
  2. jakk
    Replies:
    4
    Views:
    12,381
  3. Andy Lomax
    Replies:
    4
    Views:
    648
    Karl Heinz Buchegger
    Jul 20, 2005
  4. Tim Clacy
    Replies:
    8
    Views:
    406
    Tim Clacy
    May 30, 2006
  5. jean
    Replies:
    4
    Views:
    130
    James Britt
    May 20, 2005
Loading...

Share This Page