Unformatted text preview:

Introduction of C 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 application programs have been written in C 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 1970s C was invented to write an operating system called UNIX C is a successor of B language which was introduced around the early The language was formalized in 1988 by the American National Standard Institute ANSI The UNIX OS was totally written in C Today C is the most widely used and popular System Programming Language Most of the state of the art software have been implemented using C Today s most popular Linux OS and RDBMS MySQL have been written in C Why Use C C was initially used for system development work particularly 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 the 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 Structure of C Program The basic structure of a C program is divided into 6 parts which makes it easy to read modify document and understand in a particular format C program must follow the below mentioned outline in order to successfully compile and execute Debugging is easier in a well structured C program Modern Programs Databases Language Interpreters Utilities C Programs Sections of the C Program 1 Documentation 2 Preprocessor Section 3 Definition 4 Global Declaration 5 Main Function 6 Sub Programs 1 Documentation This section consists of the description of the program the name of the program and the creation date and time of the program It is specified at the start of the program in the form of comments Documentation can be represented as description name of the program programmer name date time etc or description name of the program programmer name date time etc Anything written as comments will be treated as documentation of the program and this will not interfere with the given code Basically it gives an overview to the reader of the program 2 Preprocessor Section All the header files of the program will be declared in the preprocessor section of the program Header files help us to access other s improved code into our code A copy of these multiple files is inserted into our program before the process of compilation Example include stdio h include math h 3 Definition Preprocessors are the programs that process our source code before the process of compilation There are multiple steps which are involved in the writing and execution of the program Preprocessor directives start with the symbol The define preprocessor is used to create a constant throughout the program Whenever this name is encountered by the compiler it is replaced by the actual piece of defined code The global declaration section contains global variables function declaration and static variables Variables and functions which are declared in this scope can be used anywhere in the program Every C program must have a main function The main function of the program is written in this section Operations like declaration and execution are performed inside the curly braces of the main program The return type of the main function can be int as well as void too void main tells the compiler that the program will not return any value The int main tells the compiler that the program will return an integer value Example define long long ll 4 Global Declaration Example int num 18 5 Main Function Example void main or int main User defined functions The user defined functions specified the functions specified as per the requirements of the user For example color sum division etc The program basic or advance follows the same sections as listed above Return function is generally the last section of a code But it is not necessary to include It is used when we want to return a value The return function returns a value when the return type other than the void is specified with the function Return type ends the execution of the function It further returns control to the specified calling function It is given by 1 return Or 1 return expression C Tokens Keywords Identifiers Constants Strings Operators The smallest individual units in a program are known as tokens C has the following tokens A program is written using these tokens white spaces and the syntax of the language Most of the C tokens are basically similar to the C tokens CHARACTER SET The character can be used to form word called string numbers and expression depend upon the computer on which the program is run The characters in C are grouped into the following categories 1 Letters Uppercase A B Z Lowercase a b z 2 Digits 0 1 2 9 3 Special characters comma semicolon 4 White Spaces blank space tab carriage return new line KEYWORDS Keywords are special words which has special meaning for compiler Compiler performs standard action when keywords are used It cannot be used as variable name in programs Some examples of keywords are for if else int float char class private etc IDENTIFIERS Identifiers refer to the names of variables functions arrays classes etc created by the programmer They are fundamental requirement of any language Each language has its own rules for naming these identifiers The following rules are common 1 Only alphabetic characters digits and underscores are permitted 2 The name cannot start with a digit 3 Uppercase and lowercase letters are distinct 4 A declared keyword cannot be used as a variable name CONSTANTS Constants refer to fixed values that do not change during the execution of a program There are several types of constants They include integers characters floating point numbers and strings For example 123 decimal integer 12 34 floating point integer 037 0x2 octal integer hexadecimal integer C string constant A character constant SYMBOLIC CONSTANTS A symbolic constant is a name that substitutes for a sequence of


View Full Document

IIT Delhi CS 123 - Introduction of C

Download Introduction of C
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction of C and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction of C 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?