Advertisement

Variables in C

 A variable is a name of the memory location. It is used to store date. Its value can be changed, and it can be reused many times.

It is a way to represent memory location through symbol so that it can be easily identified.

Let's see the syntax to declare a variable:

1.    type variable_list;

        The example of declaring the variable is given below:

1.    int a;

2.    float b;

3.    char c;

        Here, a,b.c are variabels. The int, float, char are the date types.

        we can also probide vaalues the declaring the variabels as given below:

1.    int a=10,b=20;//declaring 2 variable of integer type

2.    float f=20.8;

3.    char c='A';


Rules for defining variables

  • A variable can have alphabets, digits, and underscore.
  • A variable name can start with the alphabet, and underscore only. It can't start with a digit.
  • No whitespace is allowed within the variable name.
  • A variable name must not be any reserved word or keyword, e.g. int, float, etc.

 Valid variable names:

  1.  int a;
  2. int_ab;
  3. int a30;

  Invalid variable names:

  1. int 2;
  2. int a b;
  3. int long;




                                                     

Redmi Note 10T

Post a Comment

0 Comments