0% found this document useful (0 votes)
11 views

VARIABLES

Uploaded by

singineer35
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

VARIABLES

Uploaded by

singineer35
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Variables in C

A VARIABLE IN C LANGUAGE IS THE NAME


ASSOCIATED WITH SOME MEMORY LOCATION TO
STORE DATA OF DIFFERENT TYPES. THERE ARE
MANY TYPES OF VARIABLES IN C DEPENDING ON
THE SCOPE, STORAGE CLASS, LIFETIME, TYPE OF
DATA THEY STORE, ETC. A VARIABLE IS THE BASIC
BUILDING BLOCK OF A C PROGRAM THAT CAN
BE USED IN EXPRESSIONS AS A SUBSTITUTE IN
PLACE OF THE VALUE IT STORES.
C Variable Syntax

 The syntax to declare a variable in C specifies the name and the type
of the variable.

 Data type/variable name = value;


 Ex – Int a = 34;

 Data type: Type of data that a variable can store.


 Variable name: Name of the variable given by the user.
 value: value assigned to the variable by the user.
Rules for naming Variables

 1. First character must be an alphabet or underscore (_)


 2. No commas, blanks are allowed.
 3. No special symbol other than (_) allowed.
 4. Variable names are case sensitive.

We must create meaningful variable names in our programs. This


enhances readability of our programs.
C Variable Types

 The C variables can be classified into the following types:

 Local Variables
 Global Variables
 Static Variables
 Automatic Variables
 Extern Variables
 Register Variables
Constant Variable in C

A constant Variable in C is a read-only variable whose value cannot


be modified once it is defined. We can declare a constant variable
using the const keyword.

Note: We have to always initialize the const variable at the


definition as we cannot modify its value after defining.

You might also like