0% found this document useful (0 votes)
39 views15 pages

C Programming Unit1

The document provides an introduction to C programming, covering its history, features, and basic structure. It details the compilation process, including the role of the C compiler and the creation of executable files. Additionally, it explains fundamental concepts such as character sets, tokens, and identifiers in C programming.

Uploaded by

abhishek.09tke
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
39 views15 pages

C Programming Unit1

The document provides an introduction to C programming, covering its history, features, and basic structure. It details the compilation process, including the role of the C compiler and the creation of executable files. Additionally, it explains fundamental concepts such as character sets, tokens, and identifiers in C programming.

Uploaded by

abhishek.09tke
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
IBCA C-Programning UNIT -1 Introduction to C programming: History and features of C: C isa high level language. Icis both general purpose and specific purpose programming language It was developed at Bell Telephone Laboratory, USA (AT & T),in 1972 Itis developed by Dennis Ritchie, (is derived from two early programming languages sich as HCPL (Basie Combined Programming Language) and B language. The RCP. was developed by Martin Richards and B was developed by Ken Thompson In 1972, Dennis Ritchie developed new version of B and named it as C. He selected the name C for his new language because C eomee after B in alphabetical order which indicates an advancement to B. C language can runs under various operating system ineluding MS-DOS, Windows 98195 ete. Characteristics OR features of C: C is a general purpose programming language. C is a structured programing language. Helps in development of system software. Ithas rich sot of operators. 1 provides itnpact representation of express Ie allows manipulation of internal processor registers No rigid format. Any number of statements can be typed in a single line. Portability. Any C program can be run on different machines with little or no modification Supports rich set of data types Very less number of reserved words Pointet arithmetic and pointer manipulation. Ability to extend itself by adding functions to its library. Ghetan NJ, Edurite College of Management Studies, Shimogga Page 1 IBCA C-Programning Basic structure of C program: preprocessor Statements slobal declarations ain() { declarations, statements; user defined function Fig basie structure of C program Preprocessor statemen This part of the code is used to declare all the header files that will bé usedhin the program. This leads to the compiler being told to link the header files to the system libraries. Global declarations : ‘This part of the code is the part where the global variables are declared. Alll the global variable used are declared in this part. The user-defined functions are also declared in this part of the code. main() It is the major section from where the execution of the program begins. The main section involves the declaration and executable section, Braces: very C program uses a pair of curly braces({}). he left brace indicates the beginning of main() function and right indicates the end of the main() function, Declarations: ‘The declaration partis the part where all the variables, arrays, functions ete are declared. Ghetan NJ, Edurite College of Management Studies, Shimogga. Page 2 IBCA C-Programning Statements: ‘© Those are instructions to the computer to perform specific operations + They may be input-output statements, arithmetic statements, control statements and other statements, ‘They also include comments, The statements to be commented on must be enclosed within and *), © Comment statements are not compiled and executed. User defined function: ‘These are sub programs and they contain a set of statements to perfor specific task and these ‘ae written by the user Example for structure of C program: 1 write simple © program */ Hinclnde smain() t Printi(* welcome to ”) 3 Basie commande Fxplavafion include int main) t some_comments_*/ printtieto Wort: % eeteho; return 5 ) "This sa preprocessor command Tat inctades aandard input ouput header Hesidio‘h) om the C libary before coupling a C progr This isthe main faneton fom where execution af any C pengram beg ‘This indicates the beginning ofthe main function, whatever s given inside the command */* *7" in any C program, won't be considered for compilation and exceution, ‘pnntt commana prints the output onto the screen, This Command waits for any character input from keyboard ‘This command (erinates C program (nin function) and returns 0 This indiates the end ofthe main function. Ghetan NJ, Edurite College of Management Studies, Shimogga. Page3 IBCA C-Programning Compiling and executing a C program: Below are the steps to be followed for any C program to create and get the output. This is common to all C program and there is no exception whether its @ very small C program or very large C program. 1 2. 3 4, Create Compile Execute or Run Got the Output + Nowadays, both C and C++ compilers are integrated together in same development environment, © For example, Tuby CH, Burland C++ ad DevC+> provides Inegiated Develupuent Environment with compiler for both C and C++ programming language. + So, we can compile and execute both C and C++ programs in same Integrated Development Environment (IDE). 1. WHAT IS. C COMPILER? + C Compiler is @ program that converts human readable code into machine readable code. This process is called compilation. + Human readable code is a program that consists of letters, digits and special characters that we type in program window. Machine readable code is in 0"s & 1’s + For example, let’s assume that we type ” HELLO” in program window. We know that we have typed “HETT.0” in program window + But. processor knows only 01001000 for letter “H"”. 01000101 for letter “L”, 01001100 for letter “L”, 01001111 for letter “O” + Because, all C programs are executed by processor which is available in CPU. + So, entire ( source code should he converted into 0's and 1's as processor can understand only O's and 1°s, + So, compiler converts entire source code into 0’s and 1°s during compilation + Output produced by compiler is in the form of 0’s and 1's which is saved in exe file, This file is called a executahle or hinary file + This binary file is executed by processor as per logic written in source code and the output is displayed in output window 1001 100 for letter Ghetan NJ, Edurite College of Management Studies, Shimogga. Page + IBCA C-Programning How does a C program executes? Whenever a C program file is compiled and executed, the compiler generates some files with the same name as that of the C program file but with different extensions. Below Image shows the compilation process with the files created at each step of the compilation process: irate fistobj exocution ee leader [> source object file tile A Functions Every file that contains a C program must be saved with ‘c' extension. This is necessary for the compiler to understand that this is a C program file. Suppose a program file is named, first.c. The file first.c is called the source file which keeps the code of the program. Now, when we compile the file, the C compiler looks for errors. If the C compiler reports no error, then it stores the file as a .obj file of the came name, called the object file. So, here it will create the [Link]. Thie .obj file ic not executable. The process is continued by the Linker which finally gives a .exe file which is executable. Ghetan NJ, Edurite College of Management Studies, Shimogga. Pages IBCA C-Programning C programming basic concepts: C character set: Character set means the valid set of characters that a language recognizes, The character set includes letters, digits or any other sign. The following are the character set in C. igits : 0-9 Alphabets : a~z (lowercase alphabets) and A ~ Z (uppercase alphabets) Special characters : +-/ { } (90: != * blank space \&t (these are some of characters which are the building blocks and they form the basic program elements). Tokens: A token is a smallest individual unit in a program or a lexical unit, Chas following tokens, Identifiers Keywords Constants of Literals Punciuators variables Identifiers: ‘An identifier is a name given {0 the programming elements such as variables, arrays, functions ete. Itcan contain letter, digits and underscore. Its important to note that C is case sensitive and it treats uppercase and lowercase characters differently. ‘The following are some of the valid idemtifiers in C. Student amount marks!_—_total_score STUDENT "AMOUNT RANKS _AdI2 The following are some of the invalid i 34data - starts with a digit reg-no - contains a special character public - reserved word Ghetan NJ, Edurite College of Management Studies, Shimogga Page 6

You might also like