C Variables and Keywords

What is an Identifier?

Like any other programming language we must aware of the naming conventions in C Programming Language before start programming. An identifiers is a name given to program elements such as variables , arrays & functions. In the programming language C, an identifier is a sequences of alphabets or digits.Following rules must be kept in mind while naming an identifier.

  • The first character must be an alphabet (uppercase or lowercase) or can be an underscore.
  • All succeeding characters must be alphabets or digits.
  • No special characters or punctuation symbols is allowed except the underscore”_”.
  • No two successive underscores are allowed.
  • Keywords should not be used as identifiers.

What is keyword?

In C Programming Language there are set words that you cannot use as an identifier. These words are known as “reserved” words or “Keywords”. Keywords are standard identifiers and their meaning and purpose is predefined by the compiler.

There is set of 32(Thirty Two) keywords in C programming Language.

int float double long
short signed unsigned const
if else switch break
default do while for
register extern static struct
typedef enum return sizeof
goto union auto case
void char continue volatile

Note :-We cannot use keywords for declaring Variable Name,For Function Name and for declaring Constant Variable

What is variable?

Like in any other programming language, in C Programming Language Variables are identifier used to refer memory location in computer memory that holds a value for that variable, this value can be changed during the execution of the program.The size of memory block allocated and type of the value it holds is completely dependent upon the type of variable.Naming a variable in C Programming Language is an important task.

Rules for naming a variable –

  • Variable name can consist of letter, alphabets and start with underscore character.
  • First character of variable should always be alphabet and cannot be digit.
  • Keywords are not allowed to use as a variable name.
  • Blank spaces are not allowed in variable name.
  • C is case sensitive i.e. UPPER and lower case are significant.
  • Special characters like #, $ are not allowed except the underscore.
  • A variable name can be consist of 31 characters only if we declare a variable more than 1 characters compiler will ignore after 31 characters.

Recommendation :- Variable name must be readable and should be relative to its purpose.

Declaring a variable

In C Programming Language a variable must be declared before using it.Declaring a variables is the way in which a C program tells the compiler about the number of variables it needs, what they are going to be named, and how much memory they will need. It is important to have knowledge about the type of variables and the size of these types.



Here is an example of declaring an integer, which we’ve called counter. (Note the semicolon at the end of the line; that is how your compiler separates one program statement from another.)

This statement means we’re declaring some space for a variable called counter, which will be used to store integer data. Note that we must specify the type of data that a variable will store.

Declaring multiple variable

Multiple variables can be declared with one statement.



Initializing variables

We can also declare and assign some content to a variable at the same time.

This is called initialization.

Assigning variables

After declaring variables, you can assign a value to a variable later on using a statement like this:

You can also assign a variable the value of another variable, like so:

Or assign multiple variables the same value with one statement: