November 2013
Beginner
325 pages
9h 47m
English
In this chapter, we talked about local variables that only exist while a function is running. There are also variables that can be accessed from any function at any time. We call these global variables. To make a variable global, you declare it outside of a particular function. For example, you could add a lastTemperature variable that holds the temperature that was converted from Celsius. Add a global variable to Degrees:
#include <stdio.h>
#include <stdlib.h>
// Declare a global variable
float lastTemperature;
float fahrenheitFromCelsius(float cel)
{
lastTemperature = cel; float fahr = cel * 1.8 + 32.0; printf("%f Celsius is %f Fahrenheit.\n", cel, fahr); return fahr; } int main(int argc, const char * ...Read now
Unlock full access