Tuesday, 18 December 2018

Constants

Numeric Constant :
These have numeric value with a combination of sequence of digits i.e. from 0 to 9 as alone or combination of digits with or without decimal point having a positive or negative sign. These are further classified into two types:
1. Integer Constant
 2. Real Constant

1. Integer Constant :
Integer numeric constants have integer data combination of 0to 9 without any decimal point or without precision with positive or negative sign. These are classified into three types.

 They are : 1. Decimal Integer Constant
2. Octal Integer Constant
3. Hexadecimal Integer Constant Decimal Integer Constant:
* Integer constants have integer data combination of digits 0 to 9.
* It may have an optional sign, in case of absence considered as +.
* Commas, blank spaces and period should not be a part of it. Ex :12, 3, -21 etc… Octal Integer constant:
* It is a sequence of digits i.e. 0 . . . . 7.
* It may have an optional sign, in case of absence considered as +.
* Commas, blank spaces and period should not be a part of it.
* It should start with a “ 0 “(zero). Ex : 012,-0213. Hexadecimal Integer Constant:
* It is a sequence of digits i.e. (0 . . . . 9) (A . . Z) (a . . z).
* It may have an optional sign, incase of absence considered as +.
* Commas, blank spaces and period should not be a part of it.
* It should start with a “ OX or Ox “. Ex : OX3b, Ox2.

2. Real Constant : Constants having a decimal point or precision value within it having any positive or negative sign is called Real numeric Constant. It is also called floating point constant.Real numeric constants are further classified into two types. They are:
 1. Fractional form
 2. Exponential form Fractional form :
* Must have a decimal point.
* It may have an optional sign, incase of absence considered as +.
* Commas and blank spaces should not be a part of it. Ex : 3.12,2.3 Exponential form :
This offers a convenient way for writing large and small real constants. Ex: 3e4, 0.12e3
Character Constant : Character constants have either a single character or group of characters or a character with back slash used for special purpose. These are categorized into three types including the back slash character constant.
They are:
1. Single Character Constant
2. String Character Constant
3. Backslash Character Constant
1. Single Character Constant : Any character enclosed within a single quote (‘ ‘) is a Single character constant. A single character constant may be a single letter, single digit, or a special character placed within quotes. The maximum length of single character constant is 1. Ex : valid invalid ‘n’ ‘nitya’ ‘3’ ‘321’ 2. String Character Constant : A string is the combination of characters or group of characters. A string character constant or a string is enclosed within double quotes (“ “). The maximum length of string character constant is 255 characters. Ex : valid invalid “nitya” “nitya “hai welcome” hai welcome “ “welcome to 2013” 3. Backslash Character Constant : These are used in output statements like printf(), puts() etc. The different types of backslash characters are :


Identifiers


Identifiers:

Identifiers refer to the names of the variables, functions and arrays. These are user defined names consists of a sequence of letters, digits and a special character i.e. _ (underscore). Rules for 

Identifiers : First character can be a letter or _ (underscore).

Underscore “ _ “ should not be used as an identifier alone. It should be within the alphabets.  

Identifiers must be from the character set.

Identifiers are case sensitive i.e. HAI, Hai and hai are three different identifiers.

Identifiers must not start with a digit, special character or a white space.

Hyphen ( - ) should not be used in an identifier.

Always avoid single character as an identifier.

Identifiers can be of any length, but the number of characters in a variable that are recognized by a compiler varies.  Cannot use keywords as an identifiers.


Ex :
Valid            Invalid
add               “add”
 num1           -num
 count_1       count-1

Keywords


C Character Set

C Character Set 
Any language like English, Telugu etc… require alphabets to form words.
Likewise, a C programming language also need such a characters to write a C program which are called as C Character Set.

They are :
1. Letters
2. Digits
3. Special Characters
4. White Spaces.

1. Letters :

2. C language is case sensitive so it takes different meaning for lower and upper case letters. 


1. \b blank space
2. \n new line
3. \t horizontal tab
4. \v vertical tab
5. \r carriage return
6. \f form feed Delimiters 
In C programming, special characters are used for special syntactic meaning called Delimiters.
: (colon) Used for label entry.
() (parenthesis) Used for expression and enclosing the arguments in the function.
[] (square bracket) Used for describing the size of array
{} (braces) Used for beginning and ending of function blocks and main program.
; (semi-colon) Used at the end of every c statement except Control statements.


Structure of a “ C “ program


Documentation Section :
 This section consists of a comment tags giving the name of the program , the author and other details of the program which the programmer would like to use later. 

The comments are enclosed using
 /* comment */ 
         (or) 
//comment.
Ex : /* program for addition of 2 numbers */

Preprocessor Directives or Link Section :
It provides instructions to the compiler to link the functions for executing a program. 
It is also used to define symbolic constants of the program. 
To write a program this section is used to include predefined or user-define header files. 
A header file has an extension .h and these are included using “ #include “. 
Ex : #include (standard input/output header file)
       #inclide (console input/output header file)
       #define PI 3.14 (assigns symbolic name PI to the constant value 3.14)

Global Declaration Section : 
The variables that declare outside of the main function are called Global variables. 
These variables can be accessed anywhere by any function throughout the program. 
The global variables are automatically initialized with zero hence there is no chance of garbage value. The global variable declaration can be done as datatype variable1,variable2,……; 
Ex : int a,b;

Main() function Section :
Every C program must have only one main() function. 
Without this section the program will not run. 
This is the starting point for program execution.
 This section contains two parts 
1. Declaration Part 
2. Execution Part

Declaration part : 
Variables which are used in the main() program are declared by using the variable declaration statement called as Local Variable Section. 
Local variables can be declared as :
 datatype variable1,variable2,……….;
 Ex : int a,b,c; float x,y; char ch;

Execution statements : 
This section has reading, writing and processing statements having input/output functions, conditional statements, looping statements, function calling statements etc. 
this section executes all the statements and there must be atleast one statement in the execution section. 
Ex : printf(“hai welcome”); 
c=a+b; 
Both Declaration and Execution section must appear in between the opening
 “ { “ brace and closing “ } “ brace.
 The closing brace of the main() function is the logical end of the program. 
All the statements in the declaration and executable section must end with a semicolon “ ; “. 

Sub program Section or User-define function Section : 
This section contains all user-defined functions that are called in main function. 
Every sub program function section has local variable declaration section and executable section. Instead of writing the group of statements again and again in the main() function program, we can write it once in the function sub program and call the function again and again in the main() program according to the user requirement.

Uses of C Language

Why to use C 

* C was initially used for system development work in particular the programs that make up the operating system.It was initially implemented for the system that used UNIX operating system.
* C was adopted as a system development language because it produces a code that runs really as fast  as the code written in assembly language.


Some examples of the use of C might be 

1. Operating System
2. Language Compilers
3. Assemblers
4. Text Editors Editors are used to type the source program and store it on a disc.
C language uses a Turbo C editor in MS-DOS i.e. TC. UNIX system uses Vi editor.
5. Print Spoolers
6. Network Drivers
7. Modern Programs
8. Utilities
9. Database
10. Language Interpreters


Where is ‘ C ‘ useful : 

* The operating system such as UNIX , LINUX was written in C
* The compilers and interpreters for other languages was also written in C
The areas where C language is used
1. Embedded Systems
2. System Programming
3. Artificial Intelligence
4. Computer Graphics
5. Space Research
6. Image Processing
7. Game Programming


Features of ‘ C ‘: 

* C is a system programming language which provides flexibility for writing compilers , os etc.
* It is a high level language.
* C provides variety of data types both Built-in and User define.
* It contains set of operators that helps in writing the program efficiency.
* C language has an important feature called Extend-ability
* The programs can create and maintain a unique library functions.
* C has 40 keywords among which 32 were standard keywords and the remaining 8 are reserve keywords.
* It is highly portable i.e. programs written in one environment can be executed on other environment.
* C is often called as middle level language having features of both high level language and assembly level.
* C language is rich in built-in functions or standard functions (library functions).
* C language is a structured programming language , very simple and easy to learn.


Introduction to C

Introduction to C 


The root of all modern languages is “ ALGOL “ which was introduced in 1960’s.
 

In 1963 CPL (Combined Programming Language ) was developed by Cambridge University but the drawback of CPL was it is too large for using many application.

So in 1967 “Martin Richards“ develop a language called BCPL ( Basic Combined Programming Language )

In 1970 Ken Thompson developed a language B with some features of BCPL specially used in system programming. But these languages have some limitations to support development of both the business application and system software.

In 1972 “ Dennis Ritchie “ developed a programming language “ C “ at AT & T Bell laboratories which is the successor of B. 

After in 1983 ANSI formed a committee and standardized a C language which is referred as ANSI C.