Variable in C programming

What is variable?

Variable is an entity which can change during the program execution.

OR

Variable is the name of the memory place, where data is stored.

OR

Variable is just like a cup of tea.

How to create a variable

int x;
float y;
char z;

General Syntax

datatype variable_name;

As shown in the above snippet, To create a variable two things are needed...

  1. Data type
  2. Variable name

Rules for creating variable name

  1. Variable name can contains Alphabets(A-Z / a-z), Digits (0-9), and Underscore (_).
  2. Variable name must begins with an Alphabet or Underscore
  3. Spaces and Special symbols are not allowed.
  4. Keywords / Reserved words are not allowed as a variable name.
  5. Variable name should be meaningful.
  6. C is a case sensitive programming language, so age, Age, AGE all are different variables.

Some valid / invalid variable names are listed below...

Variable name Valid / Invalid
name valid
father_name valid
father's name invalid
father's_name invalid
avg. invalid
2persons invalid
person1 valid
int invalid
integer valid
intnum valid
FLOAT valid (Not good practise)
___AX valid
Previous Back to C Programming index Next

Comments

Popular posts from this blog

String in golang

Arrays in C Language

Literals in Java

Pointers in C Language

Inline V/S Block Level Element

Reserved Words in Java

Identifiers

Data Types in Go language

Printing in C programming

Variable Naming & Scope of Variable