The Keywords, Variables, and DataTypes in C are described below:-

Character Set :

  • A character set is a collection of various characters used in the program. The C language character set has alphabets, numbers, and special characters.
  • Every character set contains a distinct code value for each character in the basic C character set.
  • A character set can also contain additional characters with other code values.
  • The list of character sets are –
    • Alphabets include both lowercase and uppercase alphabets – A-Z and a-z.
    •  Numbers from 0-9
    • some important special characters include :
      ;  :  {  ,  ‘  “  | }  >  <  /  \ ~  _ [  ]  !  $  ?  *  +  =  (  )  –  %  #  ^  @  &

Tokens :

  • A Token is an identifier.
  • It can be constant, keyword, string literal, etc.
  • A token is the smallest individual unit in a program.
  • C has the following tokens: – 
    • Identifiers
    • Keywords
    • Constants
    • Operators
    • Special characters: All the characters except alphabets and digits are treated as special characters.

Identifiers :

  • Identifiers are the names given to various program elements such as variables, constants, function names, arrays, etc. by the programmer in the source code of the program.
  • It is 32 characters long ideally but finally implementation specific.
  • Every element in the program has its own distinct name but one cannot select/use any name in the program unless it conforms to a valid name in C language.

Rules for Creating Identifiers :

Identifiers are created/defined according to the following rules:

    • It consists of letters and digits but the first character must be an alphabet or underscore.
    • It may be any sequence of characters in uppercase and lowercase letters including numbers or underscore and dollar signs i.e. Both upper and lower cases of letters are allowed. The same text of different cases is also allowed.
    • An identifier must not begin with a number and cannot have the same name as any of the keywords of the JavaScript.
    • Except for the special character underscore ( _ ), no other special symbols can be used.
    • Text with double quotes is not allowed.
    • Text with a hyphen symbol is not allowed.
    • Text with space characters is not allowed.

Keywords/Reserved Words :

  • The words that are part of the standard C language library are called reserved words.
  • These reserved words have standard & predefined meanings in C.
  • They are already come with a C compiler.
  • These cannot be used as identifiers in the program (i.e., we cannot use reserved words as names for variables, arrays, objects, functions, and so on) by the programmers in his/her program. Even though, they are used in the program as identifiers, the compiler will understand the system-defined standard and predefined meaning. Therefore, it is advised that do not use/define keywords as identifiers in the program.
  • Reserved words are used to give instructions to the C compiler and every reserved word has a specific meaning.
  • Generally, all keywords are in lower case although uppercase of the same names can be used as identifiers.
  • The lists of C keywords are as follows: –
    char, while, do, typedef, auto, int, if, else, switch, case, printf, double, struct, break, static,
    long, enum, register, extern, return, union, const, float, short, unsigned, continue, for, signed, void, default, goto, sizeof, volatile.

Variables & Constants :

  • Constants and variables are the fundamental elements of each program.

Variables :

  • A variable is a data storage location in memory that can hold/store a data value and can change during the program execution(hence the name variable).
  • In other words, a Variable is an identifier whose value changes from time to time during the execution of the program as per given instructions.
  • Once a value is stored in a variable it can be accessed/fetched using the variable name.
  • Variable declaration is compulsory in C.
  • It is a named data storage location of a computer’s memory.
  • By using a variable’s name in our program, we are referring to the data stored there in memory.
  • As we know that computer’s memory is made up of a sequential collection of storage cells called bytes. Each byte is associated with a unique positive integer number(old)/hexadecimal value (new) called memory address. When we declare a variable in our program, the compiler immediately assigns that specific block of memory to hold the value of that variable. The size occupied by the memory block depends on the PC configuration. For example, on a 32-bit PC, the size of an integer variable is 4 bytes. On older 16-bit PCs integers were 2 bytes.
  • A variable may be either a single or group of data items which may contain either numeric data or character data or string data or a combination of all these.
  • If the variable is accessed before it is assigned a value, it may give a garbage value.
  • The data type of a variable doesn’t change whereas the value assigned to may change.
  • All variables must have three essential attributes –
    • the name
    • the value
    • the memory space, where the value is stored.
  • Naming Convention of a Standard Variable :-
    • We should use meaningful names for a variable as per the need of the program.
    • A variable name must start with a letter, underscore (_). The subsequent characters can be the digits (0-9).
    • C is case-sensitive, so the variable name value is not the same as the Value.
    • The name of a variable should be short/up to 10 characters practically.
  • Variable Declaration – 
    • Before any data can be stored in the memory for a program, we must first assign a name to these memory locations. It is called a variable declaration.
    • Variable declaration is done before they appear in program statements, else accessing the variables results in junk values or a garbage error.
    • Syntax :
datatype variablename;
datatype variablename1, variablename2, variablename3;
    • Examples :

int num;

float x, y, z;

  • Variable Initialization – 
    • Variable initialization is the process of assigning certain constant values to a declared variable. This is done in two ways –
      • Within a Type declaration
        • When the value is assigned at the time of variable declaration, it is called Type declaration.
        • For example –

int a = 23;
float b = 25.325;
char c = ‘p’;

      • Using Assignment statement
        • When the values are assigned to the variables just after the declarations it is called the Assignment method.
        • For example –
int num;
float x;
num= 54;
  • Types of Variables
    • Variables are classified into the following categories –

(A) On the basis of the variable’s availability, they are –  

Local Variables :

        • Advantage –
          • The use of local variables offers a guarantee that the values of variables will remain intact while the task is running
          • If several tasks change a single variable that is running simultaneously, then the result may be unpredictable. But declaring it as a local variable solves this issue as each task will create its own instance of the local variable.
          • We can give local variables the same name in different functions because they are only recognized by the function they are declared in.
          • Local variables are deleted as soon as any function is over and release the memory space that it occupies.
        • Disadvantage –
          • The debugging process of a local variable is quite tricky.
          • Common data is required to pass repeatedly as data sharing is not possible between modules.
          • They have a very limited scope.

Global Variables :

        • Advantage –
          • We can access the global variable from all the functions or modules in a program.
          • We are only required to declare a global variable single time outside the modules.
          • It is ideally used for storing “constants” as it helps us to keep the consistency.
          • A Global variable is useful when multiple functions are accessing the same data.
        • Disadvantage –
          • Too many variables are declared as global, and then they remain in the memory till program execution is completed. This can cause of Out of out-of-memory issue.
          • Data can be modified by any function. Any statement written in the program can change the value of the global variable. This may give unpredictable results in multi-tasking environments.
          • If global variables are discontinued due to code refactoring, we will need to change all the modules where they are called.

Constants & Literals :

  • Literals :
    • Literals refer to the constant values, which are used directly in the program code.
    • For example:

Here, 100 15.37 and Welcome are literals.

  • A constant is an identifier whose value can not be changed throughout the execution of a program.
  • In C there are three basic types of constants. They are –
    1. Numeric constants
      1. Integer constants
        1. Decimal integer constants
        2. Octal integer constants
        3. Hexadecimal integer constants
      2. Floating point constants
    2. Character constants
      • Single Character constants
      • String constants
    3. Symbolic constants

Numeric constants

    • Rules to form Numeric Constants :
      • No comma or blank space or hyphen is allowed in a constant.
      • It can be preceded by a – (minus) sign if desired.
      • The value should lie within a minimum and maximum permissible range decided by the word size of the computer.
      • Integer constants                          Maximum value limit
        Decimal integer                                      32767
        Octal integer                                           77777
        Hexadecimal integer                               7FFF

Integer constants :

Decimal integer constants

        • They consist of digits 0 through 9.
        • The first digit should not be a zero.
        • For example – 1,  443, 32767 etc.

Octal integer constants

        • They consist of digits 0 through 7.
        • The first digit must be zero.
        • For example – 0, 01, 0743, 0777 etc.

Hexadecimal integer constants

        • These constants begin with 0x or OX and are followed by a combination of digits taken from hexadecimal digits 0 to 9, a to f, or A to F.
        • For example – OX0, OX1, OXF77, Oxabcd etc.

Floating point constants

      • This constant has a base 10 containing a decimal point or an exponent.
      • For example – 0. , 1. ,000.2,  5.61123456, 50000.1 0.000741,
        1.6667E+3 0.006e-3 etc.

Character constants

Single Character constants

        • It consists of a single character enclosed within a single quote/apostrophes.
        • For example –  ‘A’, ‘x’, ‘3’, ‘$’ etc.

String constants

        • It consists of a sequence of characters enclosed within double quotes.
        • For example – “ Robert”,  “ Ganga ”,  “ 220*(8+3) ” etc.

Symbolic constants

      • Symbolic Constant is a name that substitutes for a sequence of characters or a numeric constant, a character constant or a string constant.
      • When a program is compiled each occurrence of a symbolic constant is replaced by its corresponding character sequence.
      • They can be used to assign names to values.
      • Syntax –

#define name text
(where ‘name’ implies a symbolic name in caps letter and ‘text’ implies value or the text.)

      • For example,
        #define printf  display
        #define MAX 100
        #define TRUE 1
        #define FALSE 0
        #define SIZE 10

(Here the # character is used for ‘preprocessor’ commands which come into action before Compiler, and it replaces the replacement text with the actual text.) 

Data Types in C :

  • Computer programs usually work with different types of data and for different work.
  • To store data inside the computer we need to first identify the type of data elements we need in our program.
  • Cyclic Nature of Datatype – Some of the data types in C have a special characteristic nature when a developer assigns value beyond the range of the data type. There will be no compiler error and the value change according to a cyclic order. This is called cyclic nature and char, int, and long int data types have this property. Further float, double, and long double data types do not have this property.
  • There are several different types of data, which may be used/stored differently within the computer memory for the program. C Language provides four basic data types viz. int, char, float and double which are widely used in the program.
  • In the C programming language, there are a total of three types of datatypes:
    1. Primitive/Basic/In-built/Fundamental/Primary Datatypes
      • All primitive data types are earlier data types such as char, int, float, long, double,  etc.
    2. Derived Datatypes
      • All derived datatypes work for primitive datatypes and are derived from primitive data types.
      • A derived datatype is formed by using one or more basic types
      • They may be built-in or user-derived data types.
      • Examples are – Class/Structures, Unions, and Array(An array is a derived data type because it cannot be defined on its own i.e. it is a collection of basic data types usually, such as integers, doubles, floats, booleans, etc.) and Pointers.
    3. User-Defined Datatypes
      • Examples are – Typedef & Enumerator.
    4. Void Datatype
  • Data Type Qualifiers/Modifiers : 
    • A modifier is a prefix attached to any basic data type that is used to indicate the modification for storage space allocated to a variable/optimize the memory size of the data type. For example – In a 32-bit processor, storage space for the int data type is 4 bit but when we use it with a modifier the storage space change as demand –
      • Short int -> Storage space is 2-bit
      • Long int -> Storage space is 8-bit
    • There are 5 modifiers available in the C programming language as follows –
      • short
      • long
      • signed
      • unsigned
      • long long
    • A short int requires less space than int and a long int may require more space than an int. If int and short int take 2 bytes, then long int takes 4 bytes.
Datatype Data Description Memory Consumed Data Range
Signed  Unsigned Total 
char Character – Single Character 1 Byte − 128 to 128 0 – 255 256
short int/int Integer – Small numbers with +ive/-ive values without decimal points (non-fractional values) 2 Byte − 32,768 to 32,767 0 – 65535 65536
long int Integer – Large numbers with +ive/-ive values without decimal points (non-fractional values) 4 Byte -2,147,483,648 to 2,147,483,647 0 to 4,294,967,295 4,294,967,296
float Lower Precision Value Floating Point Number – Small numbers with +ive/-ive values with decimal point (fractional values) 4 Byte 3.4 e−38 to 3.4 e+38    
double Higher Precision Value Floating Point Number – Large numbers with +ive/-ive values with decimal point (fractional values)  8 Byte 1.7e − 308 to 1.7e + 308  
void Special purpose type without any value.  

Format Specifiers :

  • Format specifiers work with scanf() and printf() functions to format the input and output data.
Specifiers Description/Used to represent
%c a single character
%s a string
%hi short (signed)
%hu short (unsigned)
%Lf long double
%n prints nothing
%d a decimal integer (for base 10)
%+d a decimal integer with sign specifier (for base 10)
%i a decimal integer (detects the base automatically)
%o an octal (base 8) integer
a hexadecimal (base 16) integer (Lowercase)
%X a hexadecimal (base 16) integer (Uppercase)
an address (or pointer)
a floating-point number for floats
int unsigned decimal/an address of a variable
%e or %g
a floating-point number in scientific notation (Lowercase)
%E or %G a floating-point number in scientific notation (Uppercase)
output with the % symbol

Escape Sequence :

  • There are some characters that can’t be printed by the program as output in C/C++ programming language. These are called non-graphic characters.
  • There are some non-printable characters that can be used in the program by preceding them with ‘\’ backslash character. These characters are called escape sequence.
  • An escape sequence is represented by a backslash (\) followed by one or more characters. 
  • Each escape sequence determines the code value for a single character.
  • We can use escape sequences to represent character codes.
  • The following is the list of the escape sequences – 
Escape Sequence Symbols Name  Task/Description
\n New Line or Line Feed To set output in the next line.
\t Horizontal Tab To make horizontal space in an output.
\a Bell (Beep)
\b Backspace
\r Carriage Return
\f Formatted
\v Vertical Tab
\” Double Quotes To set output with the double quotes 
\’ Single Quotes To set output with single quotes 
\? Question Mark
\\ Backslash To set \ symbol in the output
\0 Null
\000 Octal number (00 represents the number in octal)
\ xhh Hexadecimal number (hh represents the number in hexadecimal)


    Categories: C


    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.