Question:

Can anyone help in explaining this C++ code?

by Guest56053  |  earlier

0 LIKES UnLike

Hi All,

Can anyone help in explaining this type of code.

arrayData[2].Value = m_noAt = 0;

 Tags:

   Report

4 ANSWERS


  1. The value of array variable arryData[2].Value and m_noAt are both set to zero.


  2. Explanation of :  arrayData[2].Value = m_noAt = 0

    Assignment is done from right to left. Here assignment is done in two steps.

    step 1: m_noAt is set to 0

    step 2: the value of m_noAt is set to arrayData[2]

    So finally, both arrayData[2] and m_noAt is set to 0

    Hope u got the answer

  3. In C and C++ an assignment is also an expression and therefore has a value. The "value" of m_noAt = 0 is 0. This allows you to combine multiple assignments like

    arrayData[2].Value = m_noAt = 0;

    This is equivalent to

    arrayData[2].Value = (m_noAt = 0);

    Which says assign 0 to m_noAt, then assign the result of (m_noAt = 0) which is 0 to arrayData[2].Value.

    Another common way this feature is used is in code such as

    while ((c = getchar()) != 'q')

    { // do stuff }

    This assigns the result of getchar() to c and then uses the value of the assignment (also the result of getchar()) to compare with 'q'.

    Also, I assume arrayData is an array of structures or classes. One member of the class/struct is Value.

    Hope that helps,

    Jon

  4. Setting the value of arrayData[2] and m_noAt as Zero;

    arrayData[2].Value----->Third value of the array;

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.