edited by
636 views
1 votes
1 votes
#include <stdio.h>
int x = 20;
int f1() { x = x+10; return x;}
int f2() { x = x-5;  return x;}
int main()
{
  int p = f1() + f2();
  printf ("p = %d", p);
  return 0;
}
edited by

2 Answers

0 votes
0 votes

In computer programming, a global variable is a variable with global scope, meaning that it is visible (hence accessible) throughout the program, unless shadowed.

0 votes
0 votes

Undefined behavior as per C standard. 

Why? 

Associativity is only used when there are two or more operators of same precedence.

Associativity of the + operator is left to right, but it doesn’t mean f1() is always called before f2(). The output of following program is in-fact compiler dependent. 

In this case if f1() is called first output is 55. But when f2() is called first output is 40. So output is compiler dependent. If in some program output is independent of which function is called, we may say that will be the output. 

Related questions

0 votes
0 votes
1 answer
1
Anirudh Kaushal asked Apr 4, 2022
275 views
#include<stdio.h int main() { char num = '\011'; printf("%d",num); return 0; }
3 votes
3 votes
1 answer
2
Khushal Kumar asked Jul 7, 2017
637 views
#include <stdio.h>int main(){ int i = 8; int p = i++*i++; printf("%d\n", p);}
0 votes
0 votes
0 answers
3
Mak Indus asked Oct 26, 2018
261 views
Consider the following code.int x = 0, i;for (i = 0; i < 10, i++) if (i%2 && x++) x += 2;What will be the value of x?(a) 11 ...
0 votes
0 votes
1 answer
4