In this tutorial, you will learn about c constants definition and its types and c variables, data types, rules for declaring variables and how to declare a variable.
C Constants
Constants refer to fixed values.They are like any other normal variables of the program but the only difference is once you defined than their data items( values ) that never change or modify their value during execution of a program. Constants are also known as Literals.Types of constants
- Integer Constants: These are constants that contain numeric value or digits only and never change during the program run. Example: 96, 1114, 0969, etc.
- Character Constants: A character constant contains only one character enclosed in single quotes(‘’). It also represented it by providing ASCII value to it. Example: ‘D’, ‘s’, etc.
- Floating Constants: These are also known as Real Constants and that contains Decimal point values or fraction values. Example: 0.89, 1.2
- String constants: Multiple character constants that are surrounded by double quotes are treated as a string constant. Example: “Codeamy”
C Variables
Variable represents storage location which is allocated some space in memory to store data. This is nothing but we have store data in memory with the namespace, so it easier to access without remembering the complex memory address and use for future use.It stores in memory so it can be reused when needed. We represent a storage location with a symbol that can be distinguished easily. We provide a name to variable Variables values that can be manipulated during execution. It has a different type that defines which type of data variable hold.
Datatype of variable
They have a type that defines how much memory is allocated to the variable in C language and which type of data variable contains.- int
- float
- char
- double
- unsigned
For more about each datatype of variable clickhere
Rules for declaring variables in c
- Every Variable must start with a letter or underscore i.e. it can’t start with digits.
- A variable name contains alphabetical letters (a-z and A-Z) or digits (0-9).
- Use of special symbols like @,#,$,etc. in variable names is prohibited.
- Reserved words or keywords are not used as variables name like int, auto, etc.
- Variable names are case sensitive both upper and lower cases treated as different.
- Blankspace or whitespace in variable names is not allowed.
Types of variables
- Local Variable
- Global Variable
- Static Variable
For more about each type of variable clickhere
How to declare a variable
Declaration of variables should be done before to use in the c program. Memory space is not allocating to variables at the time of declaration. Declaration of variables only informs the compiler about the existence of a variable.extern int a; // variable declaration
int b, c;
Tags:
C