0% found this document useful (0 votes)
2 views1 page

Variables Note

In C programming, variables are names that refer to memory locations holding values, and they must be declared to allocate memory. There are two main types of variables: local variables, which are confined to the block or function where they are defined, and global variables, which are accessible throughout the program. Local variables require manual initialization, while global variables are automatically initialized by the system, and using the same name for both types is discouraged.

Uploaded by

Mhřžñ Řk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Variables Note

In C programming, variables are names that refer to memory locations holding values, and they must be declared to allocate memory. There are two main types of variables: local variables, which are confined to the block or function where they are defined, and global variables, which are accessible throughout the program. Local variables require manual initialization, while global variables are automatically initialized by the system, and using the same name for both types is discouraged.

Uploaded by

Mhřžñ Řk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Variables are simply names used to refer to some location in memory a location

that holds a value with which we are working.


Since C is a low-level programming language, before a C program can utilize
memory to store a variable it must claim the memory needed to store the values for
a variable. This is done by declaring variables. Declaring variables is the way in
which a C program shows the number of variables it needs, what they are going to
be named, and how much memory they will need.
Within the C programming language, when managing and working with variables,
it is important to know the type of variables and the size of these types. All
variables in C are typed. That is, every variable declared must be assigned as a
certain type of variable.

The Programming language C has two main variable types

 Local Variables
 Global Variables

Local Variables

Local variables scope is confined within the block or function where it is


defined. Local variables must always be defined at the top of a block. When
a local variable is defined - it is not initalised by the system, we must
initalise it ourself. When execution of the block starts the variable is
available, and when the block ends the variable 'dies'.

Global Variables

Global variable is defined at the top of the program file and it can be visible
and modified by any function that may reference it. Global variables are
initalised automatically by the system when we define them. If same
variable name is being used for global and local variable then local variable
takes preference in its scope. But it is not a good practice to use global
variables and local variables with the same name.

You might also like