Advertisement
dmilicev

global and local variables v1.c

Oct 4th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int a=2,b=5;    // global variables
  4.  
  5. int sum(int a)
  6. {
  7.     // in this function sum() a is local variable and a=3 because sum(3)
  8.     printf("\n In function sum() \t a=%d \t b=%d \n",a,b);
  9.  
  10.     return a+b; // b is global variable and b=5
  11. }
  12.  
  13. int main()
  14. {
  15.     // global variables
  16.     printf("\n In main() before calling function sum(3) \t a=%d \t b=%d \n",a,b);
  17.  
  18.     // corrected quotes "%x"
  19.     printf("\n Result is %d \n", sum(3));
  20.  
  21.     // global variables
  22.     printf("\n In main(), after calling function sum(3) \t a=%d \t b=%d \n",a,b);
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement