Ad Code

Responsive Advertisement

Basic Building Block Of Any Language.

BASIC BUILDING BLOCKS

 



It includes:

  • Variables
  • Constants
  • Identifiers
  • Qualifiers
  • Keywords
  • Operators
  • Data Types

All these are collectively called as TOKENS

 

  • Variables :

It is the value that can be changed or changes itself. In computer programming the variable is the facility to store data.The current value of the variable is the data actually stored in that variable

Variable can be defined as the space or location in memory that can store some value and that value can be changed during the execution of program eg: age, time, salary.

 

  • Constants

It is the value that cannot be changed neither changes itself. Constant is the space or location  on memory that can store some value and that value cannot be changed during the execution of program.

Although a constant's value is specified only once, a constant may be referenced many times in a program. Using a constant instead of specifying a value multiple times in the program can not only simplify code maintenance, but it can also supply a meaningful name for it and consolidate such constant bindings to a standard code location (for example, at the beginning). eg: pie, G, g, A are the universal constants.

 

  • Identifiers

The variables or constant may be referenced by identidiers. Identifier is the name given to variable or constant (location in memory) to access its values (values in that location).

 

  • Keywords

Keywords are the preserved words whose meaning is predefined to the compiler. Whenever compiler comes across those words it performs the appropriate task. There are 32 preserved words (keywords) in C language. eg: goto, break, continue etc.

 

  • Operators

Operators are the special symbols which when applied on operands gives us manipulated results and the result depends on the type of operator applied.

 

Types of Operator



 

We can categorize the operators on two basis:

a)    On the basis of number of operands used: Based on this category there are three types of operator:

1. Unary operator

2. Binary operator &

3. Terniary operator.

Unary operators works on one operand, Binary operator works on two operands and Terniary operator works on three operands.

 

b)    On the basis of operation performed: Based on this category there are eight types of operator.

 

1.    Arithmetic Operator :

 

Operator name

Syntax

Unary plus

+a

Addition (sum)

a + b

Assignment by addition

a += b

Unary minus (negation)

-a

Subtraction (difference)

a - b

Assignment by subtraction

a -= b

Multiplication (product)

a * b

Assignment by multiplication

a *= b

Division (quotient)

a / b

Assignment of division

a /= b

Modulo (remainder)

a % b

Assignment of modulo

a %= b

 

2.    Assignment Operator

 

Basic assignment

a = b

 

3.    Relational / Comparison Operator

 

Operator name

Syntax

Less than

a < b

Less than or equal to

a <= b

Greater than

a > b

Greater than or equal to

a >= b

Not equal to

a != b

Equal to

a == b

 

4.    Logical Operator

 

Operator name

Syntax

Logical negation (NOT)

!a

Logical AND

a && b

Logical OR

a || b

 

5.    Increment / Decrement Operator

 

Operator name

Syntax

Prefix increment

++a

Postfix increment

a++

Prefix decrement

--a

Postfix decrement

a--

 

6.    Conditional Operator

 

ternary conditional

a ? b : c

 

7.     Bitwise Operator

 

Operator name

Syntax

Bitwise left shift

a << b

Bitwise right shift

a >> b

Bitwise one's complement (NOT)

~a

Bitwise AND

a & b

Bitwise OR

a | b

Bitwise XOR

a ^ b

 

8.    Some Special Operators

 

Operator name

Syntax

Function call

a()

Array subscript

a[b]

Indirection (dereference)

*a

Address-of (reference)

&a

Member by pointer

a->b

Member

a.b

Cast

(type) a

Comma

a , b

size-of

sizeof(a)
sizeof(type)

Allocate storage

malloc, calloc, realloc

De allocate storage

free

 

  • Data Types

Data type tells us that what type of value we can work on C, what will be the space required in memory for storage for that particular type of value and what will be the range of value we can store in that location.

We can categorize data type in two flavours:

  1. Primary Data Type
  2. Secondary Data Type

At this very beginning stage our study is restricted to Primary Data Type. Following is the figure dealing with its type.

 

PRIMARY DATA TYPE

  1. Numeric
    1. Integer

                                       i.    Short int

                                      ii.    Signed int

                                     iii.    Unsigned int

                                     iv.    Long int

    1. Real

                                       i.    Float

                                      ii.    Double

                                     iii.    Long double

  1. Non Numeric
    1. Character

                                       i.    Signed char

                                      ii.    Unsigned char

INTEGER

 

Type

Size (in bytes)

Range

Format Specifier

short int

2

-32768 to +32767

%d

signed int

2

-32768 to +32767

%d

unsigned int

2

0 to 65535

%u

long int

4

-2147483648 to +2147483647

%ld

 

REAL

 

Type

Size (in bytes)

Range

Format Specifier

Precision

float

4

3.4e-38 to 3.4e+38

%f

6

double

4

1.7e-308 to 1.7e+308

%lf

12

long double

8

3.4e-4932 to 3.4e+4932

%le

15

 

CHARACTER

 

Type

Size (in bytes)

Range

Format Specifier

signed char

1

-128 to +127

%c

unsigned char

1

0 to 255

%c

 

VARIABLE DECLARATION:

 

It is the process to reserve space in memory for data values, where those spaces are identied by the name of the variable for further reference.

 

Syntax           :           <data type name> <variable name>

Eg                    :           int age; // by default takes signed int

This very declaration makes the compiler to reserve two byte of space in memory and identifies it with the name age.

VARIABLE INITIALIZATION:

 

It is the process to assign initial value to variable at the time of declaration. By default it takes garbage value (depends on storage class specifiers - will be discussed later).

 

 

Syntax           :           <data type name> <variable name> = <initial value>

Eg        :           int age = 10; // by default takes signed int

This very declaration makes the compiler to reserve two byte of space in memory and identifies it with the name age.

C PROGRAM STRUCTURE

 

Statements

Example

1. Documentation / Commnet Section

/*Sample Program*/

2. Header File Inclusion

#include<stdio.h>

3. Macro Definition

#define MAX 10

4. Global Variable Declaration

int x;

5. Subfunction(s)

<RT> <Function Name>(<AL>)

{

  //body of function

}

6. Main function

main()

{

  //body of main

}


 

  1. Documentation Section : Basically this section is suggested for programmers further reference, like a note to their statement or for what the program has been developed. This does not participate in the actual solution of the problem thus is enclosed within the pair of “ /* “ & “*/ “ known as comment. Whatever statements are written in comment, those are ignored by compiler.
  2. Header File Inclusion : First of all we must know what is header file. A header file contains the definitions of predefined functions in compiled format which can be reused in our program. There are many header files and what type of functions are stored in it is identified by its name followed by extension .h. So whenever we need any predefined functions to be used in our program, we must first include it in our program. This should be the very first statement in our program however it depends on programmers need.
  3. Macro Definitions : A macro is the feature of C Preprocessor whereby a macro may be declared to accept a varying number of arguments. It is an abbreviation. Details will be discussed later.
  4. Global Variable Declaration : Global variables are those variable which occupies space in memory till program terminates and can be accessed from anywhere within the program. So, if we require such shared variables, we have to declare it just after the inclusions of header file and macro definition if any.
  5. Subfunction(s) : These are self contained block of statement capabale to perform a particular task. It is based on the concept of modularization. Thus if we want to break our program into subprograms, subfunction(s) are defined. Again it depends on the need of the programmer, its not compulsory. Details will be discussed later.
  6. Main function : Also known as Primary Function. It is the function from where execution of program begins and returns the integer value or control to the operating system. It is the controller of our program. That’s why also known as Master Function or Controller Function. Thers must be atleast and atmost one main function in our program.

 

COMPILATION PROCESS

 

First of all we make our source file with an extension .c, now the code is expanded based on Preprocessor Directives used and is stored in a file having .i extension. From this code compiler checks for syntax errors. If it is error free, complier converts it to the assembly language of the machine being used. This is stored in file having .asm extension. Now the assembler creates .obj file. Then linking and loading software makes the link with other files if included in source code and those files are loaded in memory. Now the making process creates .exe file which is executed/run and gives our output. Meanwhile at back scene another file is created having .bak extension which keeps the back-up of source code.

Consider the pictorial representation for clarification:



Compilation Process in C

 

SAMPLE PROGRAM

 

/*Hello Word Program*/

#include<stdio.h>

main()

{

  clrscr();

  printf(“Hello Friends”);

}




Post a Comment

1 Comments

Close Menu