What will be the result produced by the following if a=5 initially
5*a++;
Answers
what is your question I not understood I think 5^a is your question
so the answer is 5^5=3125
Answer:
For a=5, what is the value of b = a + a++ in C programming?
All the answers that say it yields some particular answer are both right and wrong, but mostly wrong. This is broken C code that doesn’t mean anything. It needs to be corrected.
The expression has undefined behavior because a is both read and written in the same expression, in such a way that the order is not defined. This doesn’t just mean the read and write can occur in either order.
Undefined behavior is defined as:
behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements
The standard goes on to say:
NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).
It has no meaning. In a very real sense, it isn’t C. A compiler is not required to warn you about it (though some will do so). It need not produce a result. Your program can be rejected by the compiler, it can crash when you run it, it can quietly produce some seemingly meaningful result, or it can do literally anything. (The standard joke is that it make demons fly out of your nose. Of course it can’t, but if it did, that would not violate the C standard.)
The wording in the C standard that says this is undefined changed a bit between the 1999 and 2011 editions, but the meaning is essentially the same. In C99:
Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.
Elsewhere, the standard explains that violating a “shall” requirement that’s not part of a constraint results in undefined behavior.
In C11:
If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined.
Do not waste time running this code to see what it does in your implementation, or trying to argue that it should produce one particular result, or one of a small set of results depending on the order of evaluation. The code is broken. Fix it.
Whatever b = a + a++ was intended to mean (and we can’t really be sure of that), there is a simpler, clearer, and unambiguous way to express that intent. For example, you might write b = 2 * a++ or b = a + a; a ++; — if that’s what you meant.
Explanation:
if you are pleased with answer in turn
please subscribe my youtube chanel(Ramakrishna Nallangari youtube channel) for my effort
search for nallangari in google and find ramakrishna nallnagari and then click it and subscribe