Thursday 11 July 2013

ABOUT C - K MANOHAR GOUD

9866550012

ABOUT C

What is C?

C is a compiler based programming language supports both high level and low level statements to interact directly with the hardware.

Development of C Language

The C programming language evolved from a succession of programming languages developed at Bell Laboratories in early 1970s. It was not until the late 1970s that this programming language began to gain widespread popularity and support. This was because until that time C compilers were not readily available for commercial use outside of Bell Laboratories.
The C language was the outcome of Dennis Ritchie’s work on a project in Bell Laboratories, to invent a suitable high level language for writing an Operating System which manages the input and output devices of a computer, allocates its storage and schedules the running of other programs.
UNIX operating system is written in the C language. Hence the Unix Operating system has C as its standard programming language. In fact over 90% of the operating system itself is written in the C language. So originally C language was designed and implemented on the Unix Operating System.

C as a general purpose Language

C is a high level, procedural/structured, and general purpose programming language and resembles few other high level languages such as Fortran, Pascal, and PL/1. However, we cannot call the C language as a “Purely High Level Language”.
C stands somewhere between the high-level languages meant for carrying on special activities and the low level languages such as assembly language of a machine because of some features like “System Independence”, “Limited Data Type”, “High Flexibility”, it is considered as a powerful language C has also become popular because of its portability across systems.

History of C

YearLanguageDeveloped byRemarks
1960ALGOLInternational CommitteeToo general, Too abstract
1963CPLCambridge UniversityHard to learn, Difficult to implement
1967BCPLMartin RichardsCould deal with only specific problems
1970BKen Thompson AT & T Bell LabsCould deal with only specific problems
1972CDennis Ritchie AT & T Bell LabsLost generality of BCPL and B restored
Early 80’sC++Bjarne Stroustrup AT & TIntroduces OOPs to C.

Features of C

-    Simple, versatile, general purpose language
-    Programs are fast and efficient
-    Has got rich set of operators
-    more general and has no restrictions
-    can easily manipulates with bits, bytes and addresses
-    Varieties of data types are available
-    separate compilation of functions is possible and such functions can be called by any C program
-    block-structured language
-    Can be applied in System programming areas like operating systems, compilers & Interpreters, Assemblers etc.,

II. Programming Basics

Components of a program

1.    Constants
2.    Variables
3.    Operators
4.    Statements
So, before writing serious programming we must be clear with all the above components of programs. According to above example every program is a set of statements, and statement is an instruction to the computer, which is a collection of constants, variables, operators and statements.

Constants

A constant is a fixed value, which never altered during the execution of a program.
Constants can be divided into two major categories:
1.    Primary Constants
2.    Secondary Constants

Data Types

The kind of data that the used variables can hold in a programming language is known as the data type.
Basic data types are as follows:
1.    Numeric Data Type
2.    Non-Numeric Data Type
3.    Integer Data Type
4.    Real Data Type
5.    Logical Data Type
6.    Enumerated Data Type
1.    Numeric Data Type: Totally deals with the numbers. These numbers can be of integer (int) data type or real (float) data type.
2.    Non-Numeric Data Type : Totally deals with characters. Any character or group of characters enclosed within quotes will be considered as non-numeric or character data type.
3. Integer Data Type :   Deals with integers or whole numbers. All arithmetic operations can be achieved through this data type and the results are again integers.
4.    Real Data Type :  deals with real numbers or the numeric data, which includes fractions. All arithmetic operations can be achieved through this data type and the results can be real data type.
5.    Logical or Boolean Data Type :  can hold only either of the two values TRUE or FALSE  at a time. In computer, a 1 (one) is stored for TRUE and a 0 (zero) is stored for FALSE.
6. Enumerated Data Type :  Includes the unstructured data grouped together to lead to a new type. This data type is not standard and us usually defined by user.
Ex.
    Week_days = { “sun”, “mon”, “tue”, “wed”, “thu”, “fri”, “sat” };
    Directions = {”North”, “East”, “West”, “South” };
The following table shows the standard data types with their properties.
Keyword
Range: low
Range: high
Digits of precision
Bytes of memory
Format-ID
char
-128
127
n/a
1
%c
int
-32, 768
32, 767
N/a
2 (on 16 bit processor)
%d
long
-2,147, 483, 648
2, 147, 483, 647
N/a
4
%ld
float
3.4 x 10-38
3.4 x 1038
7
4
%f
double
1.7 x 10-308
1.7 x 10308
15
8
%lf
long double
3.4 x 10-4932
3.4 x 10-4932
19
10
%Lf

Wednesday 10 July 2013

C BASIC QUESTIONS AND ANSWERS - K MANOHAR GOUD

9866550012
C BASIC QUESTIONS AND ANSWERS 

Why are all header files not declared in every C program?

- Declaring all header files in every program would lead to increase in the overall file size and load of the program. It is not a good programming. 
- The choice header files that you want to declare in the program depends on the commands/functions you want to use in the program. Each header file contains different commands and functions. So we use only the files relevant to our program.


What is a newline escape sequence?

- A newline escape sequence is represented by the \n character.
- It is used to insert a new line while displaying the output data.
- To add more spaces you can use more \n characters.

What are pre-processor directives?

- Pre-processor directives are placed at the beginning of a C program. They begin with # symbol.
- This is the place, where library files are specified depending on the functions to be used in the program.
- Pre-processor directives are also used for declaration of constants.

What are header files? What are their uses?

- Header files are also called as library files.
- They carry two important things: the definitions and prototypes of functions being used in a program.
- For example: stdio.h is a header file that contains definition and prototypes of commands like printf and scanf.

Why is a semicolon (;) put at the end of every program statement?

- It is done for parsing process and compilation of the code.
- A semicolon acts as a delimiter. This tells the compiler where each statement ends, and can proceed to divide the statement into smaller elements for checking the syntax.

Are comments included during the compilation stage and placed in the EXE file as well?

- No, comments encountered by the compiler are disregarded.
- Their only purpose is guidance and ease of programmer. They have no effect on the functionality of the program.

What is the purpose of main( ) function?

The function main() calls / invokes other functions within it. The execution of the program always starts with main() function.
The main() function is :
- The first function to start a program
- Returns int value to the environment which called the program
- It can be called recursively.
- It is a user defined function, except the name
- Like other functions, main(0 function can receive arguments. It has a) argument count and b) argument vector(string argument)      

Differentiate between #include<...> and #include "..."

- #include<...> means that the directories other than the current one will be searched for the header file.
- #include "..." means that the current directory will be searched for the header file before any other directories.

Give an example of escape sequence in c.

• Newline character is the example of escape sequence in c.
• It is represented by symbol \n and is placed at the of control string.
• It is composed of 2 characters but is translated by the compiler into single character.
• It instructs the computer to move to the next line before the information is printed.
• Example: printf(“welcome to c “\n”) ;

Which function is used to input the values during execution of a program?

• The function scanf is used to input the values during execution of a program.
• Scanf stands for scan function or scan formatting.
• Syntax: scanf(“%d”, &n);
• %d shows the data type of value entered and the value is stored in’ n’.
• It is used where a numeric value or character is to be read into simple variable.


Tuesday 9 July 2013

HISTORY OF C FAMILY LANGUAGE - K MANOHAR GOUD


History of the C family of languages

1972 - The precursor to C, the language B, is developed at Bell Labs. The B language is fast, easy to maintain, and useful for all kinds of development from systems to applications. The entire team that designed the language is immediately fired for behavior unbefitting a telephone company employee, and the project is handed to Dennis Ritchie. He alters the language to be incomprehensible, difficult to maintain, and only useful for systems development. He also designs in a pointer system guaranteed to give every program over 500 lines a pointer into the operating system.
1982 – It is discovered that 97% of all C routine calls are subject to buffer overrun exploits. C programmers begin to realize that initializing a variable to whatever happens to be lying around in memory is not necessarily a good idea. However, since enforcing sensible variable initialization would break 97% of all C programs in existence, nothing is done about it. 
1984 – The number of operating systems bad pointers can get to has been dramatically increased.  
1985 – A variant of C with object oriented capabilities, called C With Classes, is ready to go commercial. However, the name C With Classes is considered too clear and easy for outsiders to understand, so the commercial version is called C++.
1986 – C becomes so popular that industry analysts recommend writing business applications in it. They argue that applications written in C will be portable to many different systems. Many of these industry analysts are suspected of being under the influence of hallucinogens.
1988 – Industry analysts finally run out of LSD. After their hallucinations fade, they notice that business apps written in C take five times longer to produce, and are still not portable. They stop recommending that business apps be written in C, except for a minority that switch to crack cocaine and start recommending business apps be written in C++ because “object orientation will result in code reuse”.
1990 – By this time, all C compilers have turned into C++ compilers. But, since most C++ programs do not use any of the object oriented features of the language, this means in practical terms that bloated code structures with pointers into the operating system are now being compiled with an object-oriented compiler.
1990 – After hiring some industry analysts that switched from crack to sniffing glue, Sun decides to create a language called Oak to program set-top television boxes. Since all their programmers have had stilted C syntax imprinted into their DNA by this time, the new language borrows heavily from C and C++ syntax. However the set-top boxes don’t have an operating system for bad pointers to get to, so pointers are eliminated from the language.
1994 – Someone at Sun finally realizes what a stupid idea it was to develop a special language just for set-top television boxes. The language is renamed Java and repositioned as an “Internet” language that is supposed to be portable to many platforms. This works well as a marketing campaign, since less than 3% of people in the industry at this time realize what the Internet is, and since hallucinating industry analysts continue to be suckers for the mythical idea of "portability to different platforms".
1995 - Sun offers free psychedelic mushrooms to industry analysts, who immediately start writing articles about how Java is the future of programming because of its portability and integration with the Internet.
Mid 1996 – 17,468,972 articles appear about how Java is the future of programming. The age of Java applets in web pages begins.
Late 1996 – Programmers trying to produce actual web pages with applets that really work commit mass suicide out of frustration and depression. Industry analysts increase their dosage of hallucinogens to compensate.
1997 – Taking the advice of hallucinating industry analysts, Corel decides to rewrite all their applications, including WordPerfect, in Java. The end result is the first known word processor that is slower to use than a typewriter.
1998 – Realizing that the applet thing is fading fast, Sun repositions Java again, this time as a server language. They steal the design of Microsoft Transaction Server and convince everyone to pretend they created the design.
1999 – Java 2 Enterprise Edition is introduced to the rave reviews of drunk and stoned industry analysts. 21,499,512 articles are written about it, but no one actually uses it because it’s immature and expensive.
2000 – J2EE finally works, sort of. Just about the time all the Java vendors are ready to start making money on it, Microsoft announces .NET, which includes almost all the features of J2EE except the outrageous cost. In fact, Microsoft decides to give .NET away free for Windows users. Scott McNealy is so outraged he files another irrational lawsuit against Microsoft.
.NET includes a new C-family language, C#, pronounced “C-pound”, continuing the tradition of languages in this family having stupid names.
2001 – Microsoft’s marketing department realizes that no one in marketing has ever talked to a live Microsoft product developer. They have lunch with one and discover that the pronunciation is actually supposed to be “C sharp”.
2002 – C# is introduced as part of the release version of Microsoft .NET. C++ developers on the Microsoft platform rejoice over the concept of “managed code”, which means they finally receive the same automatic memory management features that Visual Basic has had since 1991 and Java has had since 1995.






INTRODUCTION TO C LANGUAGE - K MANOHAR GOUD

9866550012

INTRODUCTION TO C LANGUAGE

C is a general purpose high level language that was originally developed by Dennis M. Ritchie to develop the Unix operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.
In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard.
The UNIX operating system, the C compiler, and essentially all UNIX applications programs have been written in C. The C has now become a widely used professional language for various reasons.
  • Easy to learn
  • Structured language
  • It produces efficient programs.
  • It can handle low-level activities.
  • It can be compiled on a variety of computer platforms.

Facts about C

  • C was invented to write an operating system called UNIX.
  • C is a successor of B language which was introduced around 1970
  • The language was formalized in 1988 by the American National Standard Institute (ANSI).
  • The UNIX OS was totally written in C By 1973.
  • Today C is the most widely used and popular System Programming Language.
  • Most of the state of the art software's have been implemented using C.
  • Today's most popular Linux OS and RBDMS MySQL have been written in C.

Why to use C ?

C was initially used for system development work, in particular the programs that make-up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as code written in assembly language. Some examples of the use of C might be:
  • Operating Systems
  • Language Compilers
  • Assemblers
  • Text Editors
  • Print Spoolers
  • Network Drivers
  • Modern Programs
  • Data Bases
  • Language Interpreters
  • Utilities

C Programs

A C program can vary from 3 lines to millions of lines and it should be written into one or more text files with extension ".c" for example hello.c