Initializing Variables in C Program
When you declare a variable, you instruct the compiler to set aside storage space for the variable. However, the value stored in that space—the value of the variable—isn’t defined. It might be zero, or it might be some random “garbage” value. Before using a variable, you should always initialize it to a known value. You can do this independently of the variable declaration by using an assignment statement, as in this example:
int count; /* Set aside storage space for count */ count = 0; /* Store 0 in count */
Role of Variable name declaretion in C
To use variables in your C programs, you must know how to create variable names. In C, variable names must adhere to the following rules:
1) The name can contain letters (a to z and A to Z), digits (0 to 9), and the underscore character (_).
2) The first character of the name must be a letter. The underscore is also a legal first character, but its use is not recommended at the beginning of a name. A digit (0 to 9) cannot be used as the first character.
3) Case matters (that is, upper- and lowercase letters). C is case-sensitive, thus, the names count and Count refer to two different variables.
4) C keywords can’t be used as variable names. A keyword is a word that is part of the C language. (A complete list of the C keywords can be found in Appendix B, “Reserved Words.”) .
Datatypes in C language
A data type specifies the type of data that a variable can store such as integer, floating, character, etc. There are the following data types in C language.
What is use of data type in C?
Data Types in C. … char: The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers. int: As the name suggests, an int variable is used to store an integer. float: It is used to store decimal numbers (numbers with floating point value) with single precision.
What is user defined data type in C?
C supports the features “typedef” that allows users to define the identifier which would represent an existing data type. … “Enum” is the keyword and “identifier” is the user defined data type that is used to declare the variables. It can have any value enclosed within the curly braces.
Why do we use data type?
In computer science and computer programming, a data type or simply type is an attribute of data which tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support common data types of real, integer and boolean.
How do you declare a variable in C?
A variable in C language must be given a type, which defines what type of data the variable will hold….
Datatype of Variable
- char : Can hold/store a character in it.
- int : Used to hold an integer.
- float : Used to hold a float value.
- double : Used to hold a double value.
Role of Nameing Variable
- Variable name must begin with letter or underscore.
- Variables are case sensitive
- They can be constructed with digits, letters.
- No special symbols are allowed other than underscore.
- sum, height, _value are some examples for variable name
Type of variable in c language
- Local variable
- Global variable
- Environment variable