#include <stdio.h>
int arr[] = { 10, 20, 30, 40, 50 };
static int count ;
inc() {
return ++count;
}
int main()
int
main()
{
arr[count++]=inc();
printf("%d ", arr[count]);
printf
(
"%d "
, arr[count]);
printf("%d ", arr[0]);
, arr[0]);
https://ideone.com/5LOuqj
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.
yes it is 30 2
Undefined behaviour
https://stackoverflow.com/questions/23990968/please-explain-the-output-of-following-c-code
the answer is 30,2 here
undefined behavior
64.3k questions
77.9k answers
244k comments
80.0k users