2 votes 2 votes #include <stdio.h> int arr[] = { 10, 20, 30, 40, 50 }; static int count ; inc() { return ++count; } int main() { arr[count++]=inc(); printf("%d ", arr[count]); printf("%d ", arr[0]); } https://ideone.com/5LOuqj Programming in C data-structures programming-in-c output + – Gurdeep Saini asked Jan 14, 2019 • edited Feb 20, 2019 by Gurdeep Saini Gurdeep Saini 1.7k views answer comment Share Follow See all 8 Comments See all 8 8 Comments reply Show 5 previous comments Mk Utkarsh commented Jan 14, 2019 reply Follow Share when post-increment happens a temporary variable is created which stores the initial value but original variable is incremented at the moment. that's why when inc() is executing it finds count with value 1. 0 votes 0 votes Gurdeep Saini commented Jan 15, 2019 reply Follow Share https://ideone.com/5LOuqj yes it is 30 2 0 votes 0 votes smsubham commented Mar 7, 2020 reply Follow Share Undefined behaviour https://stackoverflow.com/questions/23990968/please-explain-the-output-of-following-c-code 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes the answer is 30,2 here Priyadrasta Raut answered Jan 15, 2019 Priyadrasta Raut comment Share Follow See all 23 Comments See all 23 23 Comments reply Show 20 previous comments Shaik Masthan commented Feb 22, 2019 reply Follow Share here calculated address of 'a', which can't effect by first executing LHS or RHS part of '=' 0 votes 0 votes srestha commented Feb 23, 2019 reply Follow Share have u any reference? I havenot got how r u telling that for = it is giving undefined behaviour 0 votes 0 votes HanuamntappaBudihal commented Dec 29, 2019 reply Follow Share It's not undefined expression , [ ] has higher precedence than = , it will evaluate first,including the expression inside the []. Answer must be 30 2. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes undefined behavior https://stackoverflow.com/questions/23990968/please-explain-the-output-of-following-c-code omprakash889 answered Feb 19, 2019 omprakash889 comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes undefined behaviour Sequence Point Problem. arr[count++]=inc(); arr[count++]=++count; omprakash889 answered Feb 19, 2019 omprakash889 comment Share Follow See 1 comment See all 1 1 comment reply Shaik Masthan commented Feb 20, 2019 reply Follow Share it's undefined behaviour due to which side of '=' evaluate first but not sequence problem ! 0 votes 0 votes Please log in or register to add a comment.