Character Set :

  • Character set is the collection of various characters used in 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.
  • List of character sets are –
    • Alphabets including 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 and arrays etc.
  • 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 valid name in C language.

Rules for Creating Identifiers :

Identifiers are created/defined according to the following rules:

    • It consists of letters and digits.
    • First character must be an alphabet or underscore.
    • Both upper and lower cases of letters are allowed. Same text of different case is allowed.
    • Except the special character underscore ( _ ), no other special symbols can be used.
    • Text with double quotes not allowed.
    • Text with hyphen symbol does not allow.
    • Text with space character does not allow.

Keywords/Reserved Words :

  • The words that are part of the standard C language library are called reserved words.
  • These reserved words have standard & predefined meaning in C.
  • They are already come with C compiler.
  • They cannot be used as program-defined identifiers by the programmers in his/her program.Even though, they use in the program as  identifiers, compiler will understand  the system defined standard and predefined meaning.Therefore, it is advise that do not use/define keyword as identifier in the program.
  • Generally all keywords are in lower case although uppercase of 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 normal/simple variable is a data storage location in memory that can hold a value and can change during program execution.
  • Variable is an identifier whose value changes from time to time during execution of the program.
  • It is a named data storage location of 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 values(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 32 bit PC’s the size of an integer variable is 4 bytes. On older 16 bit PC’s integers were 2 bytes.
  • A variable may be either a single or group of data items which may contain either a numeric data or a character data or a string data or combination of all these.
  • If the variable is accessed before it is assigned a value, it may give 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.
  • 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 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 through 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 of it is called Assignment method.
        • For example –
int num;
float x;
num= 54;
  • Types of Variables
    • Variables are classified into following categories –

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

Local Variables :

        • Advantage –
          • The use of local variables offer 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 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 which it occupies.
        • Disadvantage –
          • The debugging process of a local variable is quite tricky.
          • Common data 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 only require to declare 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 declared as global, then they remain in the memory till program execution is completed. This can cause 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.
  • (B) On the basis of …, they are –  

Constants :

  • 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 – (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 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 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 single character enclosed within single quote/apostrophes.
        • For example –  ‘A’, ‘x’, ‘3’, ‘$’ etc.

String constants

        • It consists of 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 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 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 comes into action prior to Compiler, and it replaces the replacement text by the actual text.) 

Data Types :

  • 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 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, 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.
  • Data Type Qualifiers/Modifiers : 
    • Modifier is a prefix attached with the any  basic data type which is used to indicate the modification for storage space allocated to a variable/optimize the memory size of datatype.For example – In 32-bit processor, storage space for the int data type is 4 bit but when we use it with 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 C programming language as follows –
      • short
      • long
      • signed
      • unsigned
      • long long
    • A short int requires less space than int and long int may require more space than int. If int and short int takes 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 point (non-fractional values) 2 Byte − 32,768 to 32,767 0 – 65535 65536
long int Integer – Large numbers with +ive/-ive values without decimal point (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  

Escape Sequence :

  • There are some characters which 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 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
\t Horizontal Tab
\a Bell(Beep)
\b Backspace
\r Carriage Return
\f Formatted
\v Vertical Tab
\” Double Quotes
\’ Single Quotes
\? Question Mark
\\ Backslash
\0 Null

Octal number (00 represents the number in octal)
\ xhh

Hexadecimal number (hh represents the number in hexadecimal)

     947 total views,  1 views today

    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.