





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document provides an introduction to the C Programming Language, covering its history, features, characteristics, and applications. It explains the structure of a C program, program development life cycle (compiler, linker, and loader), coding rules, comments, header files, preprocessor directives, and library functions. The document also discusses C tokens, keywords, identifiers, variables, escape sequences, and data types. Additionally, it highlights the uses of C in operating systems, embedded systems, and software development, making it a foundational guide for beginners learning C programming concepts.
Typology: Study notes
1 / 9
This page cannot be seen from the preview
Don't miss anything!






MCA First Year- KCA 102 Unit- 1 .3 Programming in C Introduction C Programing language is a general-purpose middle level (Partially low and Partially High level) Language. C is a programming language. C is one of the oldest and finest programming languages. was developed by Dennis Ritchie in 1972. It is relatively small language as its small, unambitious feature set is a real advantage: there's less to learn; C programming language is a general-purpose, procedural, structured and imperative computer programming language It is developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C Language is the most widely used computer language. It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers. It is partially low and partially high-level language means it can handle low-level and high-level activities C was invented to write an operating system called UNIX. The UNIX OS was totally written in C. It is a successor of B language which was type less The language was formalized in 1988 by the American National Standard Institute (ANSI). Most of the state-of-the-art software have been implemented using C. It can be compiled on a variety of computer platforms History of C Language In the early days, in general every language was designed for some specific purpose. like FORTRAN (Formula Translator) was used for scientific and mathematical applications, COBOL (Common Business Oriented Language) was used for business applications. Thus need of a language was recognized which could withstand most of the purposes. "Necessity is the mother of invention". This was the first step towards C was put forward by Dennis Ritchie. The C programming language was developed in 1972, at Bell laboratories by Dennis Ritchie. Initially it was designed for programming in the operating system called UNIX. After the advent of C, the whole UNIX operating system rewritten using C language only. Now almost tlvc entire UNIX operating system and the tools supplied with it including the C compiler itself are written in C. The C language is derived from the B language, which was written by Ken Thompson at AT&T Bell laboratories. The B language was adopted from a language called BCPL (Basic Combined Programming Language ), which was developed by Martin Richards at Cambridge University Characteristics of C It is a middle level language. It has the simplicity of a high-level language as well as the power of low level language. This aspect of C makes it suitable~ for writing both application' programs and system programs. It is an excellent, efficient and general-purpose structured, procedural, modular imperative programming language.
It used for mathematical, scientific, business and system software applications. C is small language, consisting of only 32 English words known as keywords (if, else, for, break etc.: The power of C augmented by the library functions provided with it. Moreover, the language is extendible since it allows the users to add their own library functions to the library. C contains control constructs needed to write a structured program hence it is also known as a structured programming language. It includes structures for selection (if.. .else, switch), repetition (while, fo do...while) and for loop exit\ (break)... The programs written in C are portable i.e. programs written for one type of computer or operating system can be run\on another type of computer or operating system C also used to develop games, an area where latency is very important i.e. computer has to react quickly on user input. Uses of C: C is a language that is used to program a wide variety of systems. Some of the uses of C are as follows: Major parts of Windows, Linux, and other operating systems are written in C. C is used to write driver programs for devices like Tablets, Printers, etc. C language is used to program embedded systems where programs need to run faster in limited memory. General Rules for programming in C
Structure of a C program In C, comments begin with the sequence /* and are terminated by /. Anything that is between the beginning and ending comments symbols is ignored by the compiler. Example: / sample program */ n C, blank lines are permitted and have no effect on the program. A non-trivial C application typically has following general portions on it: The structure of a C program looks as follows: All c programs have to follow a basic structure. A c program starts with the main function and executes instructions presents inside it. Each instruction terminated with a semicolon(;) There are some basic rules which are applicable to all the c programs:
Elements of a typical C Program Preprocessor: C libraries : Most of its intelligence is compartmentalized in libraries Almost all c programs use the “stdio” or standard input/output library. Many also use the “math” library. To use a library, include the header file (I.e., “stdio.h”) at the top of the file. For most special purpose libraries (I.e., math) you need to include the library on the link line. Every C program line begins with # provides an instruction to the C preprocessor. It is executed before the actual compilation is done. Two most common directives: ◦ #include ◦ #define In our example (#include) identifies the header file for standard input and output needed by the printf(). # includes: An include directive tells the preprocessor to include the contents of the specified file at the point in the program. Path names must either be enclosed by double quotes or angle brackets. Header Files (.h): Header files contains declaration information for standard library functions or constants that are referred in programs. They are used to keep source-file size to a minimum and to reduce the amount of redundant information that must be coded. A header file can be included in following ways: 1: # include : the <> tells the preprocessor to search for the included file in a special known \include directory or directories. 2: # include “mylib.h” the double quotes (“ ”) indicate that the current directory should be checked for the header file first. If it is not found, the special directory (or directories) should be checked. 3 # include “mine\include\mylib.h” It is similar to 2, but the named relative directory \mine\include is checked for the header file mylib.h. Relative paths can also be proceeded by the .\ or ..\ notation; absolute paths always begin with a . # defines: ANSI C allows you to declare constants. The # define directive is used to tell the preprocessor to perform a search-and-replace operation. Example:
In the example above, the preprocessor will search through the source file and replace every instance of the token Pi with 3.14159 After performing the search and replace operation, the preprocessor removes the # define line. User defined function prototypes: Declares the user-written functions actually defined later in the source file. A function prototype is a statement (rather than an entire function declaration) that is placed a head of a calling function in the source code to define the function's label before it is used. A function prototype is simply a reproduction of a function header (the first line of a function declaration) that is terminated with a semi-colon. Function main () in C : Compiler identify the start of the program. Every C program has a main ( ). 'main' is a C keyword. We must not use it for any other variable. There are following four common ways of main declaration
Keywords These are reserved words, whose meaning is already known to the compiler. There are 32 keywords available in c: auto double int struct break (^) long else switch case return enum typedef char register extern union const short float unsigned continue signed for void default sizeof goto volatile do (^) static if while Identifiers A 'C' program consist of two types of elements, user defined and system defined. Identifiers is nothing but a name given to these elements. An identifier is a word used by a programmer to name a variable, function, or label. identifiers consist of letters and digits, in any order, except that the first character or label. Identifiers consist of letters and digits if any order, except that the first character must be letter. Both Upper and lowercase letters can be used
Can contain a mix of characters and numbers. However it cannot start with a number H2o First character must be a letter or underscore Number1; _area Can be of mixed cases including underscore character XsquAre my_num Cannot contain any arithmetic operators R*S+T … or any other punctuation marks… #@x%!! Cannot be a C keyword/reserved word struct; printf; Cannot contain a space My height … identifiers are case sensitive Tax != tax Variables "Variables" are simply storage locations to hold data. For every variable, some memory is allocated. The size of this memory depends on the type of the variable. For example, 2 bytes are allocated for integer type, 4 bytes are allocated for float type, etc. thus a variable is like a container that stores a ‘value’. Like we have containers at home for storing rice, dal, sugar, etc. Similar to that variable in c stores value of a constant. Example: a = 3; //a is assigned “3” b =4.7; //b is assigned “4.7” c=’A’; //c is assigned “A” Rules for naming variables in c: