In this tutorial, we are going to learn about Variables & Keywords in C Language.

The character set of C language:

Each and every language in the world requires alphabets to form words. Likewise,  a programming language also needs a set of characters to write a program. The set of characters used in a language is known as its Character Set.

Every language makes use of its own character set to form words or symbols that make up the vocabulary of the language.

C language is case sensitive. We mean that the C compiler considers lowercase and uppercase characters differently. For example, the variable name key is different from Key. C language has its own character set. The character set for ANSI Standard C (ANSI C) is as follows:

  • Uppercase alphabets: A to Z
  • Lowercase alphabets: a to z
  • Decimal digits: 0 to 9
  • Special characters: + - * / % = < > : ; , . ' " ? ! # \ ( ) { } _ [ ] & | ^ ~
  • Escape sequences: \b  \t  \v  \r  \f  \n  \\  \'  \"  \?  \0  \a

Understanding Identifiers in C:

In any language, we start learning words after we learn their alphabet. We use words to name and identify different things. These names are nothing but Identifiers.

Identifiers are names used to refer to any entity in a program. A program can contain many entities or building blocks such as data types, constants, variables, functions, arrays, etc.

An identifier is a sequence of characters. In C language identifiers can be formed by combining alphabets, digits and a special character underscore _ ‘.

For example, let’s understand the program given below:

#include <stdio.h>
void main() {
     printf("Online Tutorials Point");
}

The tokens main and printf are the names given to two functions and are called identifiers.

Some of the rules for creating a valid identifier in C are given below:

  • The first character must always be an alphabet or an underscore. The remaining other characters can be a combination of one or more alphabets, digits, and underscores.
  • No special characters other than underscore are allowed in an identifier.
  • An identifier can be of any length. However, in old (before C was standardized by ANSI), only the first 8 characters were taken into consideration by the compilers when the names were compared for equality. This limit was modified to 31 characters as per the ANSI Standard.

 Understanding Variables in C:

A variable is a name given to a memory location to store some value. Since the memory location can store different values during the execution of a program, the name used to refer to it is called a variable.

Since variables are a part of identifiers, they follow the same naming conventions. Like identifiers, a valid variable name can start with an alphabet or an underscore ( _ ) and later have a combination of one or more letters, digits, and underscores.

A few examples of valid variable names are num1, num2, total, average, etc…

When creating a variable, we should maintain the type of data (for example, integer, character, etc…) that it would store. This is called the data type of that variable. In a C program, variables should be declared before their usage.

For example, let’s consider the following statement

int num1;  //int is the data type of the variable and num1 is the variable name

The above declaration can also be combined with initialization. In such a case, the format for declaring a variable is as follows

data_type  variable_name  =  constant_value;

Given below is an example of declaring and initializing a variable in the same line of code

int num1 = 17; //Here ther variable name is num1 (integer type) and it is being initialized to a constant value 17

 Understanding Keywords in C:

There are certain predefined words as part of the programming language that has a special meaning and purpose. They are called reserved words or Keywords.

C language has 32 reserved words as per ANSI standards. They are given below

Keywords in C

The user (or a programmer) cannot redefine these keywords, i.e., the user cannot change their spellings or add new ones to the C programming language.

All reserved words in are formed using only the lowercase letters.

Keywords have special meaning and purpose, so they cannot be used as variable names.

References:

Happy Learning 🙂

Hemanth Krishna Vineel Ramayanam
I’m an Undergraduate Student at the Indian Institute of Information Technology, Design, and Manufacturing, Kurnool, Andhra Pradesh. I belong to the CSE domain.

Leave A Comment