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

Overview of Go lang

Arrays in C Language

Data Types in Go language

Creating your first html page

Say Hello world in Go lang

Arrays in Go lang

Installing go lang

String in golang

Decision Making in Go lang

Floating point Data types in Go lang