The way to define different kinds of variables in a Java program is as follows:
Where (inside/outside a method) and how (with/without keyword static) determines the kind of a variable
A C program can define 5 kinds of variables and they are defined as follows:
Where (inside/outside a method) and how (with/without keyword static) determines the kind of a variable
Parameter variables in C are the same as in Java:
Parameter variables
are defined inside the
braces ( ... ) of the
function header
Used for
short term
information storage
(used by 1 function)
Local variables in C are the same as in Java:
Local variables
are defined inside the
body of a
function
without using
keyword
static
Used for
short term
information storage
(used by 1 function)
Global variables in C are similar to public class (static) variables in Java:
Global variables
are defined
outside the
body of a
function
without
using
keyword
static
Used for
long term
information storage
(by
multiple functions
in
any C program file)
Static global variables in C are similar to private class (static) variables in Java:
Static
global variables
are defined
outside the
body of a
function
using the
keyword
static
Used for
long term
information storage
(by
multiple functions
in
same C
program file)
Static local variables in C: (no comparison in Java)
Static
local variables
are defined
inside the
body of a
function
using the
keyword
static
Used for
long term
information storage
(used by
one function)
Practice identifying the 5 kinds of variables in this C program: