2 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 4.8k views answer comment Share Follow Print See all 8 Comments 8 8 Comments reply Show 5 previous comments Mk Utkarsh commented Jan 14, 2019 reply Follow flag 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 0 replyShare Gurdeep Saini commented Jan 15, 2019 reply Follow flag https://ideone.com/5LOuqj yes it is 30 2 0 0 replyShare smsubham commented Mar 7, 2020 reply Follow flag Undefined behaviour https://stackoverflow.com/questions/23990968/please-explain-the-output-of-following-c-code 0 0 replyShare Please log in or register to add a comment.
0 0 votes the answer is 30,2 here Priyadrasta Raut answered Jan 15, 2019 Priyadrasta Raut comment Share Follow See all 23 Comments 23 23 Comments reply Show 20 previous comments Shaik Masthan commented Feb 22, 2019 reply Follow flag here calculated address of 'a', which can't effect by first executing LHS or RHS part of '=' 0 0 replyShare srestha commented Feb 23, 2019 reply Follow flag have u any reference? I havenot got how r u telling that for = it is giving undefined behaviour 0 0 replyShare HanuamntappaBudihal commented Dec 29, 2019 reply Follow flag It's not undefined expression , [ ] has higher precedence than = , it will evaluate first,including the expression inside the []. Answer must be 30 2. 0 0 replyShare Please log in or register to add a comment.
0 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 0 reply Please log in or register to add a comment.
0 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 1 1 comment reply Shaik Masthan commented Feb 20, 2019 reply Follow flag it's undefined behaviour due to which side of '=' evaluate first but not sequence problem ! 0 0 replyShare Please log in or register to add a comment.