fundamental of c

Fundamental of C

Character set :-  The Character set is the fundamental row material of any language and they are used to represent information like natural language. The Character set is also useful to build the program.

The Character set in C language are grouped into two categories.

1. Source Character set :-

  •   Alphabet

                 Upper Case  A to Z

                 Lower Case   a to z

  •   Digits

                 0,1,2,3,4,5,6,7,8,9

  •   Special Characters

                +  –  * /  = % & # ! ? ^ ” ‘ /  | < > ( )                  [  ]  {  } : ; . , ~ @ !

2. Escape sequence/Escape Character set:-

  •  White space

                 \n, \b, \t, \v

C Tokens :- C Tokens are the smallest building block of a C program which a simple program.

C Supports Six Types of Tokens :

  1. Keywords
  2. Identifiers
  3. Constants
  4. Strings
  5. Operators
  6. Special Symbols

Keywords :- Keywords are the word that are reserved by the program because the word has special meaning in the every programming language. Has a set of the keyword that cannot be use as variable name, identifier.

   Example : int, float, double, if, else, break,                      continue etc.

Identifiers :- Identifiers are the name that given to various program elements. Such as variable, symbols, constant and function.

   Example : int num;

NOTE :-  num are identifiers and int are keywords.

Modifiers :- Modifiers are keywords in c which changes the meaning of basic data type in c. It specifies the amount of memory space to be allocated for a variable. Modifiers are prefixed with basic data types to modify the memory allocated for a variable.

There are basic modifiers in C language :

Long : This can be used to increase the size of current data type to 2 more byte.

Short : Short is use to reduce the size of data type.

Signed : When signed is used number may be positive or negative.

Unsignd : When the modifiers unsigned is used the number is always positive.

Variables :-  C variables are names used for storing a data value to locations in memory. The value stored in the c variables may be changed during program execution.

Declaration of variables :-

Declaration of variable in c can be done using following syntax :

       data_type variable_name;   

or   data_type variable1, variable2,,variablen ;

For example,

  • Int a;
  • Float a,b;

Initialization of variables :-

C variables can be initialized with the help of assignment operator "=".

        data_type variable_name= constant;  

       or             variable_name= constant;      

For example,

  • Int a = 10;
  • a = 10;

Scope of Variables :-

In C language, a variable can be either of global or local scope.

Global Variable :- A Global variables are defined outside of all the functions, generally on top of the program. The global variables will hold their value throughout the life­time of your program.

Local Variable :-  A local variable is declared within the body of a function or a block. Local variable only use within the function or block where it is declare.

Constant :- C Constants are also like normal variables. But, only difference is, their values cannot be modified or changed by the program once they are defined.

Syntax: const data_type variable_name;

Types of constant :

Constant type

  data type (Example)

Integer constants

  • int (53, 762, -478 etc )
  • unsigned int (5000u, 1000U etc)
  • long int, long long int (483,647 2,147,483,680)

Real or Floating point constants

  • float (10.456789)
  • doule (600.123456789)

Octal constant

  • int (Example: 013 /*starts with 0 */)

Hexadecimal constant

  • int (Example: 0x90 /starts with 0x/)

character constants

  • char (Example: ‘A’, ‘B’, ‘C’)

string constants

  • char (Example: “ABCD”, “Hai”)

Data Types in C

Each variable in C has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. Let us briefly describe them one by one:

Following are the examples of some very common data types used in C:

  • Char :The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers.
  • Int : As the name suggests, an int variable is used to store an integer.
  • Float :It is used to store decimal numbers (numbers with floating point value) with single precision.
  • Double :It is used to store decimal numbers (numbers with floating point value) with double precision.

C language supports 2 different type of data types:

1.  Primary data types:

These are fundamental data types in C namely integer(int), floating point(float), character(char) and void.

2.  Derived data types:

Derived data types are nothing but primary datatypes but a little twisted or grouped together like arraystuctureunion and pointer. These are discussed in details later.

 DataTypes 

 Size (bytes)

int

 at least 2,   usually 4

char

        1

float

        4

double

        8

Typedef :- The typedef is an advance feature in C language which allows us to create an alias or new name for an existing type or user defined type.

The syntax of typedef is as follows:

     Syntax: typedef data_type new_name;

     Example typedef int myint;

Execution and Compilation of C programs :

The compilation and execution process of C can be divided in to multiple steps:

  • Preprocessing - Using a Preprocessor program to convert C source code in expanded source code. "#includes" and "#defines" statements will be processed and replaced actually source codes in this step.
  • Compilation - Using a Compiler program to convert C expanded source to assembly source code.
  • Assembly - Using a Assembler program to convert assembly source code to object code.
  • Linking - Using a Linker program to convert object code to executable code. Multiple units of object codes are linked to together in this step.
  • Loading - Using a Loader program to load the executable code into CPU for execution.

Error :- Error is a abnormal condition whenever it occurs execution of the program is stopped.

Types of Error in C

  • Compile Time Error
  • Run time error

Compile time error or syntax errors

If any error is generated at the time of compilation is known as compile time error, in general these are raised while break down the rules and regulation of programming language.

Example : Missing semicolon, writing keyword in upper case, writing variable declaration, initialization after calling clrscr() function.

Run time error

If any error is generated at run time is known as runtime error, in general these are raised because of writing wrong logics in the program.

Example : Calling function without existence,  divide by zero ( a/0 ).

 
This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free