Sunday, 1 July 2012

charset identifier and keyword


C Programming Keywords and Identifiers:

Character set:

Character set are the set of alphabets, letters and some special characters that are valid in C language.

Alphabets
Uppercase: A B C  ....................................  X Y Z
Lowercase: a b c  ......................................  x y z

Digits:
0 1 2 3 4 5 6  8 9


Special Characters:     

Special Characters in C language
 



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

The white spaces used in C programs are: blank space, horizontal tab, carriage return, new line and form feed.






































Identifiers and Keywords:

Identifiers

In C programming, identifiers are names given to C entities, such as variables, functions, structures etc. Identifier are created to give unique name to C entities to identify it during the execution of program. For example:

int money;
int mango_tree;

Here, money is a identifier which denotes a variable of type integer. Similarly, mango_tree is another identifier, which denotes another variable of type integer.

Rules for writing identifier
  1. An identifier can be composed of letters (both uppercase and lowercase letters), digits and underscore '_' only.
  2. The first letter of identifier should be either a letter or an underscore. But, it is discouraged to start an identifier name with an underscore though it is legal. It is because, identifier that starts with underscore can conflict with system names. In such cases, compiler will complain about it. Some system names that start with underscore are _fileno, _iob, _wfopen etc.
  3. There is no rule for the length of an identifier. However, the first 31 characters of an identifier are discriminated by the compiler. So, the first 31 letters of two identifiers in a program should be different.
Tips for Good Programming Practice :
Programmer can choose the name of identifier whatever they want. However, if the programmer choose meaningful name for an identifier, it will be easy to understand and work on, particularly in case of large program.


Identifiers are names given to various program elements such as variables, functions, and arrays. Identifiers consist of letters and digits, in any order, except that the first character must be a letter. Both uppercase and lowercase letters are permitted and the underscore may also be used, as it is also regarded as a letter. Uppercase and lowercase letters are not equivalent, thus not interchangeable. This is why it is said that C is case sensitive. An identifier can be arbitrarily long.
The same identifier may denote different entities in the same program, for example, a variable and an array may be denoted by the same identifier, example below.

int sum, average, A[10]; // sum, average and the array name A are all identifiers.

The _ _func_ _ predefined identifier:-

The predefined identifier __func__ makes a function name available for use within the function. Immediately following the opening brace of each function definition, _ _func_ _ is implicitly declared by the compiler in the following way:


static const char _ _func_ _[] = "function-name";

where function-name is the name of the function.
consider the following example
 
 
#include <stdio.h>
void func1(void)    {
         printf("%s\n",__func__);
         return;
}
int main() {
     myfunc();
}
The output would be
func1

Keywords

Keywords are reserved words that have standard predefined meanings. These keywords can only be used for their intended purpose; they cannot be used as programmer defined identifiers. Examples of some keywords are: int, main, void, if.

 

Keywords in C Language:

auto double int struct
break else long switch
case enum register  typedef
char extern return union
continue for signed void
do if static  while
default goto sizeof volatile
const float short unsigned

 

 

History of the C Programming Language

                                        
                     

             The C Programming Language


History:

C was developed at Bell Laboratories in 1972 by Dennis Ritchie. Many of its principles and ideas were taken from the earlier language B and B's earlier ancestors BCPL and CPL. CPL ( Combined Programming Language ) was developed with the purpose of creating a language that was capable of both high level, machine independent programming and would still allow the programmer to control the behavior of individual bits of information. The one major drawback of CPL was that it was too large for use in many applications. In 1967, BCPL ( Basic CPL ) was created as a scaled down version of CPL while still retaining its basic features. In 1970, Ken Thompson, while working at Bell Labs, took this process further by developing the B language. B was a scaled down version of BCPL written specifically for use in systems programming. Finally in 1972, a co-worker of Ken Thompson, Dennis Ritchie, returned some of the generality found in BCPL to the B language in the process of developing the language we now know as C.

C's power and flexibility soon became apparent. Because of this, the Unix operating system which was originally written in assembly language, was almost immediately re-written in C ( only the assembly language code needed to "bootstrap" the C code was kept ). During the rest of the 1970's, C spread throughout many colleges and universities because of it's close ties to Unix and the availability of C compilers. Soon, many different organizations began using their own versions of C causing compatibility problems. In response to this in 1983, the American National Standards Institute ( ANSI ) formed a committee to establish a standard definition of C which became known as ANSI Standard C. Today C is in widespread use with a rich standard library of functions.


Significant Language Features:

C is a powerful, flexible language that provides fast program execution and imposes few constraints on the programmer. It allows low level access to information and commands while still retaining the portability and syntax of a high level language. These qualities make it a useful language for both systems programming and general purpose programs.

C's power and fast program execution come from it's ability to access low level commands, similar to assembly language, but with high level syntax. It's flexibility comes from the many ways the programmer has to accomplish the same tasks. C includes bitwise operators along with powerful pointer manipulation capabilities. C imposes few constraints on the programmer. The main area this shows up is in C's lack of type checking. This can be a powerful advantage to an experienced programmer but a dangerous disadvantage to a novice.

Another strong point of C is it's use of modularity. Sections of code can be stored in libraries for re-use in future programs. This concept of modularity also helps with C's portability and execution speed. The core C language leaves out many features included in the core of other languages. These functions are instead stored in the C Standard Library where they can be called on when needed.. An example of this concept would be C's lack of built in I/O capabilities. I/O functions tend to slow down program execution and also be machine independent when running optimally. For these reasons, they are stored in a library separately from the C language and only included when necessary.


Areas of Application:

The C programming language is used in many different areas of application, but the most prolific area is UNIX operating system applications. The C language is also used in computer games:
  • UNIX operating system
  • computer games

NUMBER SYSTEMS

NUMBER SYSTEMS:


Number Systems Concepts:


The study of number systems is useful to the student of computing due to the fact that number systems other than the familiar decimal (base 10) number system are used in the computer field.

Digital computers internally use the binary (base 2) number system to represent data and perform arithmetic calculations. The binary number system is very efficient for computers, but not for humans. Representing even relatively small numbers with the binary system requires working with long strings of ones and zeroes.
The hexadecimal (base 16) number system (often called "hex" for short) provides us with a shorthand method of working with binary numbers. One digit in hex corresponds to four binary digits (bits), so the internal representation of one byte can be represented either by eight binary digits or two hexadecimal digits. Less commonly used is the octal (base 8) number system, where one digit in octal corresponds to three binary digits (bits).

In the event that a computer user (programmer, operator, end user, etc.) needs to examine a display of the internal representation of computer data (such a display is called a "dump"), viewing the data in a "shorthand" representation (such as hex or octal) is less tedious than viewing the data in binary representation. The binary, hexadecimal , and octal number systems will be looked at in the following pages.

The decimal number system that we are all familiar with is a positional number system. The actual number of symbols used in a positional number system depends on its base (also called the radix). The highest numerical symbol always has a value of one less than the base. The decimal number system has a base of 10, so the numeral with the highest value is 9; the octal number system has a base of 8, so the numeral with the highest value is 7, the binary number system has a base of 2, so the numeral with the highest value is 1, etc.
Any number can be represented by arranging symbols in specific positions. You know that in the decimal number system, the successive positions to the left of the decimal point represent units (ones), tens, hundreds, thousands, etc. Put another way, each position represents a specific power of base 10. For example, the decimal number 1,275 (written 1,27510)* can be expanded as follows:
1 2 7 510
5 x 100 = 5 x 1 = 5
7 x 101 = 7 x 10 = 70
2 x 102 = 2 x 100 = 200
1 x 103 = 1 x 1000 = 1000
------
1275 10
Remember the mathematical rule that n0 = 1, or any number raised to the zero power is equal to 1.
Here is another example of an expanded decimal number:
1 0 4 0 610
6 x 100 = 6 x 1 = 6
0 x 101 = 0 x 10 = 0
4 x 102 = 4 x 100 = 400
0 x 103 = 0 x 1000 = 0
1 x 104 = 1 x 10000 = 10000
--------
10406 10

* When doing number system problems, it is helpful to use a subscript to indicate the base of the number being worked with. Thus, the subscript "10" in 127510 indicates that we are working with the number 1275 in base 10.

TRY THIS: Expand the following decimal number:
5 1 3 010



i uplode when i have efective way to express ......................... tnx u

flowchart and algorithm

Formal Problem Solving Steps :

• Understand the Problem
• Develop an Algorithm
• Refine the Algorithm
• Create an Action Plan
• Generate a Solution
• Test the Solution

Algorithms:

• Step by step method to solve a problem

• Must include ALL required information

E.G. ~ Recursive Algorithms:

Algorithm Product (a, b)
Recursively find the product of a and b.
if b = 1 then
return a
else
return Product (a, b − 1) + a;
end if
Algorithm Power (a, n)
Compute an, where n is a non-negative integer.
if n = 0 then
return 1
else
return Power (a, n − 1) × a
end if
Algorithm Move (N, source, dest, spare)
Move N disks from peg source to peg dest using peg spare in the Tower of Hanoi puzzle.
if N = 1 then
print “move 1 disk from source to dest”
else
Move (N − 1, source, spare, dest);
print “move 1 disk from source to dest”
Move (N − 1, spare, dest, source);
end


Relational Operators:

• Determine how one value relates to another
– Equal to ==
– Not equal to !=
– Less than <
– Greater than >
– Less than or Equal to <=
– Greater than or Equal to >=

Lamp working testing flow chart :

Follow the Flowchart:

• May have to redraw the flowchart several
times to get it into a form that fits one of the
C structures.
• Rules to Flow charting
– A complex task can be shown as a single block
– Start with the simplest flowchart possible
– Any process can be replaced by a sequence
– Any process can be replaced by a control
structure


Relational Operators:

• Determine how one value relates to another
– Equal to ==
– Not equal to !=
– Less than <
– Greater than >
– Less than or Equal to <=
– Greater than or Equal to >=

Lamp working testing flow chart :


Diffrence between. compiler and IInterpreter & High & Low Level Languages

The difference between compiler and interpreter :










alt text


Definition of compiler:

Compiler is a program that translates a computer program written on one computer language to another computer language. A "compiler" is primarily used for programs that translate source code from a high level language to a lower level language (e.g., assembly language or machine language). A program that translates from a low level language to a higher level one is a decompiler. A compiler for a relatively simple language written by one person might be a single, monolithic, piece of software. When the source language is large and complex, and high quality output is required the design may be split into a number of relatively independent phases, or passes. Having separate phases means development can be parceled up into small parts and given to different people. It also becomes much easier to replace a single phase by an improved one, or to insert new phases later.

Definition of Interpreter:


Interpreter is a program that translates an instruction into a machine language and executes it before proceeding to the next instruction..... A high-level programming language translator that translates and runs the program at the same time. It translates one program statement into machine language, executes it, and then proceeds to the next statement. This differs from regular executable programs that are presented to the computer as binary-coded instructions. Interpreted programs remain in the source language the programmer wrote in, which is human readable text. Interpreted programs run slower than their compiler counterparts. Whereas the compiler translates the entire program before it is run, interpreters translate a line at a time while the program is being run. However, it is very convenient to write an interpreted program, since a single line of code can be tested interactively.



Main difference:

Compiler and interpreter are both translates used for converting the source program to computer readable form.
Major difference between compiler and interpreter is that compiler converts the high level language program (source code) to machine readable form as a whole (like C, C++ and Java program -there we write the entire program and then compile and the errors will be shown like 25 errors, 16 errors etc...) while an interpreter converts the H.L.L. to M.L. line by line (like VB - there we write a statement like if (condition) and if we omit the 'then' statement and press enter - we cant move to second line since the interpreter will show an error and after typing 'then' only we can move to the next line.


Differences Between High & Low Level Languages :


A high level language is a language for programming computers which does not require detailed knowledge of a specific computer, as a low-level language does.High-level languages do not have to be written for a particular computer, but must be compiled for the computer they will work with.High-level languages are closer to human language than low-level languages, and include statements like GOTO or FOR which are regular words

On the other hand, a low level language is a computer programming language that is close to machine language.Machine language is at the lowest level, because it is the actual binary code of 1s and 0s that the computer understands.Assembly languages are low- level languages which are translated into machine code by an assembler.Each assembly language instruction corresponds to one machine language instruction, but assembly language is easier notation for the programmer to use than machine code.

Programing Language

A programming language is used to write computer programs such as :

1.Applications :


Definition: The terms executable, program and application are often used to mean the same thing. Strictly though a program or executable refers to one file that can be run. An application can be anything from a single executable program to something the size of Ms Word, made up of many executables.

 

2.Utilities : 

Definition: A utility is a small program that performs a task. Developers often write small utilities to do some useful task. Because they are basically throw away programs they are rarely tested or written to be maintainable.

Servers :

 Definition: Server has two related meanings.
  1. A Server is a computer that provides services used by other computers. For example a web server serves up web pages.
  2. A Server is a computer program that has an associated Client program. This might run on the same computer or on another networked computer. My Sql is an  example of a database server program. Developers write clients that communicate with the server.

And Systems Programs :


 A program is written as a series of human understandable computer instructions that can be read by a compiler and linker, and translated into machine code so that a computer can understand and run it.



 programming languages


low-level language :


 A machine language or an assembly language. Low-level languages are closer to the hardware than are high-level programming languages, which are closer to human languages.



high-level language:



 A programming language such as C, FORTRAN, or Pascal that enables a programmer to write programs that are more or less independent of a particular type of computer. Such languages are considered high-level because they are closer to human languages and further from machine languages. In contrast, assembly languages are considered low-level because they are very close to machine languages.
The main advantage of high-level languages over low-level languages is that they are easier to read, write, and maintain. Ultimately, programs written in a high-level language must be translated into machine language by a compiler or interpreter.
The first high-level programming languages were designed in the 1950s. Now there are dozens of different languages, including Ada, Algol, BASIC, COBOL, C, C++, FORTRAN, LISP, Pascal, and Prolog.



Softwere : Systm and Applecation S/W

 system software and application software:

"Software is a set of instructions, programs which enable the computer to perform specified task. In other words, software is nothing but binary code instructions which control the hardware".

In most of the organizations the computer is a valuable resource. Among the resources that a computer has are processing time, storage space, printers, terminals and information. The management of these resources is performed largely by a type of system software called an operating system. When users interact with the computer the interaction is with system software.

There are two broad categories of software, system software and application software.

System software is a set of programs that manage the resources of a computer system, so that they are used in an optimal fashion, provide routine services such as copying data from one file to another and assist in the development of applications programs.

System software consists of programs that assist the computer in the efficient control, support, development and execution of application programs. Application software on the other hand, performs specific tasks for the computer user.

System software:


They can be broadly classified in to three types.
  1. System control programs control the execution of programs, manage the storage and processing resources of the computer and perform other management and monitoring functions. Other examples are DBMS and communication monitors.
  2. System support programs provide routine service functions to the other computer programs and computer users. Ex. Libraries, utilities, job accounting etc.
  3. System development programs assist in the creation of application programs.
    System programs are developed and sold by both computer companies and specialized software firms.

Application Software:

It is a program written for, or by, a user to perform a specific job. General purpose application software such as electronic spreadsheet has a wide application. Specific purpose application software, such as payroll and sales analysis is used only for the application for which it is designed.
The system software controls the execution of the application software and provides other support functions such as data storage.




Typical examples of software applications are word processors, spreadsheets, and media players.

Multiple applications bundled together as a package are sometimes referred to as an application suite. Microsoft Office and OpenOffice.org, which bundle together a word processor, a spreadsheet, and several other discrete applications, are typical examples. The separate applications in a suite usually have a user interface that has some commonality making it easier for the user to learn and use each application. And often they may have some capability to interact with each other in ways beneficial to the user. For example, a spreadsheet might be able to be embedded in a word processor document even though it had been created in the separate spreadsheet application.

User-written software tailors systems to meet the user's specific needs. User-written software include spreadsheet templates, word processor macros, scientific simulations, graphics and animation scripts. Even email filters are a kind of user software. Users create this software themselves and often overlook how important it is.

In some types of embedded systems, the application software and the operating system software may be indistinguishable to the user, as in the case of software used to control a VCR, DVD player or Microwave Oven.