C Constants and Variables

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

  1. Integer Constants: These are constants that contain numeric value or digits only and never change during the program run. Example: 96, 1114, 0969, etc.
  2. 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.
  3. Floating Constants: These are also known as Real Constants and that contains Decimal point values or fraction values. Example: 0.89, 1.2
  4. 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.
  1. int
  2. float
  3. char
  4. double
  5. unsigned
For more about each datatype of variable clickhere

Rules for declaring variables in c


  1. Every Variable must start with a letter or underscore i.e. it can’t start with digits.
  2. A variable name contains alphabetical letters (a-z and A-Z) or digits (0-9).
  3. Use of special symbols like @,#,$,etc. in variable names is prohibited.
  4. Reserved words or keywords are not used as variables name like int, auto, etc.
  5. Variable names are case sensitive both upper and lower cases treated as different.
  6. Blankspace or whitespace in variable names is not allowed.

Types of variables

  1. Local Variable
  2. Global Variable
  3. 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;

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form