Skip to content

Instantly share code, notes, and snippets.

@s3f
Created January 12, 2017 14:34
Show Gist options
  • Save s3f/3a9a6e2de83d43c99d12bb3275ccba95 to your computer and use it in GitHub Desktop.
Save s3f/3a9a6e2de83d43c99d12bb3275ccba95 to your computer and use it in GitHub Desktop.
Chapter 30- Functions created by s3f - https://repl.it/FG0B/3
/* Functions
In a lot of textbooks, the programs you see are usually brief (20 - 30 lines) however, in the real world, programs are much much longer and therefore it helps a lot if you can break your code into sections. Doing so ensures that it'll be much more easier to write and maintain your code.
Breaking programs into smaller functions is called structured programming
Now the following example program is a simple demonstration of the difference between global and local variables.
*/
#include <stdio.h>
int g1 = 10; // This is a gloabal variable
main()
{
float l1 = 9.0; // Local variable
printf("%d %.2f\n", g1, l1); //Prints the first global and local variable
prAgain() // calls our first function
return 0;
float g2 = 19.0;
prAgain()
{
int l2 = 5;
printf("%d %.2f\n",g1, g2, l2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment