2. Contents
• Variables in C
• Data types
• Types of Variables
• Scope of Variables
• C keywords
3. Variable
• A variable is actually a named value in the
RAM, stored while executing a C program
• Variable name is defined once inside a
program block but can be reset as many
times as you want (if it is not a constant
var).
• If variable is to be kept constant, the
keyword const is used before the type of
the variable and the name of variable.
(discussed later)
• sizeof() function is used to check the size of
variable in bytes
• Type casting is the process of converting
one variable type to another variable type
4. It is the type of variable that tells the loader, how much
RAM spaces in terms of individual bit should be reserved
for a data.
0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 1
1 1 1 1 1 1 1 1
27 26 25 24 23 22 21 20
RAM locations already have 0’s and 1’s in it. When we define but do not initialize a variable, it uses the
Already available data as garbage entry. RAM is made up of logic gates/flip flops that are made of transistors.
9. Wide Character (compiler specific)
• The C and C++ standard libraries include a number of facilities for dealing with wide
characters and strings composed of them. The wide characters are defined using
datatype wchar_t, which in the original C90 standard was defined as
• "an integral type whose range of values can represent distinct codes for all members of
the largest extended character set specified among the supported locales" (ISO
9899:1990 §4.1.5)
• Both C and C++ introduced fixed-size character types char16_t and char32_t in the 2011
revisions of their respective standards to provide unambiguous representation of 16-bit
and 32-bit Unicode transformation formats, leaving wchar_t implementation-defined.
The ISO/IEC 10646:2003 Unicode standard 4.0 says that:
• The width of wchar_t is compiler-specific and can be as small as 8 bits.
• Consequently, programs that need to be portable across any C or C++ compiler should
not use wchar_t for storing Unicode text.
• The wchar_t type is intended for storing compiler-defined wide characters, which may be
Unicode characters in some compilers.
10. Scope of variables (More info Here)
• A scope is a region of the program, and the scope of variables refers to the area of the program
where the variables can be accessed after its declaration.
• In C every variable defined in scope. You can define scope as the section or region of a program
where a variable has its existence; moreover, that variable cannot be used or accessed beyond
that region.
• In C programming, variable declared within a function is different from a variable declared
outside of a function. The variable can be declared in three places.
These are:
11. Scope of variables
• Local Variable
• Variables that are declared within the function
block and can be used only within the function is
called local variables.
• Global Variable
• Variables that are declared outside of a function
block and can be accessed inside the function is
called global variables.
• Formal Parameters
• Variables that are declared inside the
parenthesis of definition of a function
Information about argc argv
#include <stdio.h>
/* global variable definition */
int z;
int main (int argc, char *argv[])
{
/* local variable definition and initialization */
int x, y;
/* actual initialization */
x = 20;
y = 30;
z = x + y;
printf ("value of x = %d, y = %d and z =
%dn", x, y, z);
return 0;
}
12. C Keywords
• Words that are prohibited to be used
as variable names
• Sometime Upper case variables are
used if the exact keyword has to be
used. More about case sensitive