What is variables?
C variable is a named location in a memory where a program can manipulate the data. This location is used to hold the value of the variable.The value of the C variable may get change in the program.C variable might be belonging to any of the data type like int, float, char etc.Type | Description | |||
---|---|---|---|---|
char | Typically a single octet(one byte). This is an integer type. | |||
int | The most natural size of integer for the machine. | |||
float | A single-precision floating point value. | |||
double | A double-precision floating point value. | |||
void | Represents the absence of type. |
Variable Definition in C
A variable definition tells the compiler where and how much storage to create for the variable. A variable definition specifies a data type and contains a list of one or more variables of that type as follows −Here, type must be a valid C data type including char, w_char, int, float, double, bool, or any user-defined object; and variable_list may consist of one or more identifier names separated by commas. Some valid declarations are shown here −
The line int i, j, k; declares and defines the variables i, j, and k; which instruct the compiler to create variables named i, j and k of type int.
Variables can be initialized (assigned an initial value) in their declaration. The initializer consists of an equal sign followed by a constant expression as follows −
Some examples are −
For definition without an initializer: variables with static storage duration are implicitly initialized with NULL (all bytes have the value 0); the initial value of all other variables are undefined.
Comments
Post a Comment