retagged by
1,916 views
0 votes
0 votes

If a= 10 then what will be the value of b in a C language code
.
If b= a++ + a++ + a++;
.

  1. 30.
  2. 23.
  3. 33.
  4. Undefined behaviour
retagged by

4 Answers

Best answer
2 votes
2 votes
x = y++;

Here, y++ is post increment operator which returns the value of y, and increments y. What happens to the returned value? It is assigned to x. So, this assignment or the increment happens first? This is not specified by precedence/associativity rules and is internal to the compiler implementation as C standard does not fix a strict order. To help the programmer C standard says to avoid writing codes where the order of these executions changes the output. That is, never to modify a variable more than once in an arithmetic expression. (When we have logical && and || due to short circuit rules, we may skip undefined behaviour). 

Here, a++ is done 3 times in an arithmetic expression - crying

selected by
0 votes
0 votes

answer is 30 reason is there is a space between unary ++ and a binary + 

0 votes
0 votes
Its 33..

This is Cascading... and it is evaluated from right to left..

Related questions

2 votes
2 votes
3 answers
1
Laahithyaa VS asked Sep 9, 2023
895 views
. What will be the value returned by the following function, when it is called with 11?recur (int num){if ((num / 2)! = 0 ) return (recur (num/2) *10+num%2);else return 1...
1 votes
1 votes
1 answer
4
Prajwal Bhat asked Aug 19, 2016
1,083 views
#include<stdio.h>int main(){int a = 10, b = 20, c = 30, d = 40;printf("%d%d%d",a, b, c);printf("%d%d%d", d);return 0;}What is the Output and when I run it I am getting so...