C Variables

In simple words, variable is a name given to memory box with a name, where we can “store” some value. Its value can be changed depending upon conditions and it can be reused many times.

  • A variable can support different type of data such as integer, float, character etc
  • Value of variables can be changed according to the information passed to the program.
  • You can perform different set of operation to the variables.

Rules for naming C Variable

  • A Variable name must begin with letter or underscore.
  • Variables are case sensitive
  • You can use letters & digits in variable names.
  • No special symbols can be used other than underscore.
  • sum, city, person_2, _value are some examples for Variable name

Characters allowed in C variable name:

You can use Underscore(_), Capital Letters ( A – Z ), Small Letters ( a – z ) and Digits ( 0 – 9 ) while choosing a variable name. Blanks, Commas and other special symbols are not allowed in variable naming. Variable name Should not be Reserved Word.


Example of Valid or Invalid Variable Names

These are some of the examples of valid variable names for city

  • city
  • City
  • City1
  • _City
  • my_city
  • city_1
  • city_of_person
  • status_flag
  • _city1

Invalid Variable Names

  • 1city
  • 1_city
  • city 1

Declaring & initializing C Variable

  • First, you need to declare a variable in the C program before to use.
  • Memory space is not created for a variable during declaration. It happens only on variable definition.
  • Variable initialization assigs a value to the variable.
S.No Type Syntax Example
1. Variable declaration data_type variable_name; int x, y, z; char ch;
2. Variable initialization data_type variable_name = value; int x = 10, y = 20; ch=’l’;

Example of Variable in C Programming

Here is the simple example of C Variable:


Congratulations! Chapter Finished. Do you want to practice more?
Exercises & Assignments
  • No Content Found.
  • Interview FAQs
  • No Content Found.