Sei sulla pagina 1di 10

Introduction Let me introduce basic concept in C. The way it was designed and developed.

C was designed and developed by Dennis Ritchie in 1972. C has a predecessor called the language B. Now lets look at the basic features that were developed in B. B was developed in 1960 at the University of Cambridge mainly to overcome the defects that was there in the Basic combined programming language. Both these languages were not capable of handling the software defects the application that were existing at that time so there was a need to develop a more powerful language that could handle the software problems. That led to the development of this language C. C is called a middle -level computer language. What is this middle level computer language signify a middle level language means something in between the high and low level languages so this C combines the features of high- level language and functionality of this assembly language. A high level language is something that we users can understand and a low level language or assembly language is one that the machines can understand. So we needed a language that could bridge the gap between us and the system so that was perfectly done by the software language C. Now this C acted as a bridge between us and the system. We were able to communicate in the form of programs that could solve the current problems at hand and the results that were produced by the system were communicated to us in an understandable manner so this feature of C was most well suited for developing both application software and system software. So what is this application software mean? A Software which is generated for a specific application for a specific problem is called application software for example we are viewing the power point slides which are prepared using MS-PowerPoint we cannot use MSExcel or MS-Word in the same way to create a slide. A slide is meant to be created using the power point software so that indicates that this MS-PowerPoint is an application software meant for that particular application. What is system software? A System software is the heart beat of any computer system when we switch on any computer we see a number of processes taking place on their own that process is called booting that is when the operating system gets loaded into the computer all the desktop settings, the hardware settings, the printer settings, the scanner settings or whatever settings have been already configured in the computer are brought to their normal ranges so that the desktop can be seen for the users to start using the system. So system software is more general in nature it is common to all the computer systems whereas an application software is one which is developed for a particular reason to solve a particular task at hand. This feature of C a middle level language was most acceptable to write all these kinds of software so thats what makes C so popular.

Next we see that C is a structured language. So what is this structured language mean? The structured language allows a variety of programs in small modules. A module is nothing but a small set of statements. There are two different ways to handle a problem. Either we can solve the entire problem in series of steps or we can divide the problem into smaller sub tasks and handle each sub task and when we combine it together we can get the find a solution. So C prefers to follow the second approach. It normally divides the problem into smaller sub tasks and it writes a small set of statements called module to solve that problem. Then all these modules are combined together to form the entire program. So that is what gives C a structure. It has a beginning, it has an ending and it has a body which is divided into several modules so this feature of C makes it easy for debugging. Debugging is nothing but finding, detecting and recovering from errors so any mistake that is there in the program can be easily rectified and every time we make a change to a set of statements they have to be tested and seen whether after the change is made the program is executed correctly and whether the final aim, the goal is achieved so for all of these C is very very efficient as well as easy to be handled. Its easy for debugging, easy for testing once the program its errors are removed and its easy for maintenance. What is this software maintenance? Now say we have a program that performs addition and subtraction using the same set of statements we can easily perform the other arithmetic calculations by a small change of a symbol. So when the software is maintained it saves as the entire time and the coding to start the entire program again and perform similar problems of the same nature so having a single program at hand we can solve other problems of a similar nature by just making small modifications in one or two statements in the coding. C gives us that particular advantage over other languages that were developed before it. So thats what makes programming with C more efficient as well as fast. Because everything that is related to a software starting from development of the software, Debugging of the software, testing of the software and maintenance of the software. Everything is made easier with this language so thats what makes C a very very popular language. These were just an introduction to C. What is program? Now lets move on to what is a program because C is basically a programming language. So we have to write programs using C. before we start writing a program we should know what a program is and what are the requirements that we need to know what is the information that we need before we begin to write a program. Program is nothing but a set of statements for a specific task. What is this word statement mean? Statement has been clearly explained later before that the continuation of the definition of the program is, it should be executed in a certain sequence. It is a collection of statements and they should be in a particular order.

Let us take now the definition of statement. It is an instruction formed using certain words and symbols. Now lets take the language English, we have a collection of alphabets say A to Z there are 26 alphabets but we cannot manage using these alphabets anyhow we want. There is a certain grammar there is a certain spelling for each word so unless we use these alphabets in that particular order and according to that rule English makes no sense. That is the same with C software as well it is also a software language it has a collection of elements but there are certain rules that govern the use of these elements so we have to give instructions to the computer using the words and symbols that are available in C. The first step is, we first have to know what are the words and symbols that are permitted in C. The next point is they have to be arranged according to certain rules and grammar so the next thing we need to know before we write a program are the rules that are available in C that govern the use of those words and symbols. The third one is these elements, the words and symbols have to be arranged according to the syntax. Syntax is another name for the rules that exists in the language that governs by use of its symbols. Now we are going to look into the elements of C. only when we know what all is required to write a program we will be able to study the elements in the right manner and we will be able to remember the rules that govern the use of those elements so that we can write readable, executable and understandable programs. Next we move over to the elements of C. These elements in C have to be memorized and they have to be kept in our heart so that we can use these whenever we write our programs. So we can get more familiar with these elements as we write more and more programs. Elements are Tokens in C. Token is nothing but the smallest basic element in any language that is it cannot be further simplified. That is the basic unit that is the basic component that exists in a particular language so there is another name for it. It can be called as elements or tokens. The tokens in C are classified as C character set, C delimiters, C Keywords, Identifiers, Constants and Variables. Now we will see each of these in detail. Coming to the C character set. The C character set has four components. Classified as Letters, Digits, White spaces and special characters. Now what are the letters that are available in this language C? We have all the English alphabets included in this C language as well. Both in their capital form as well as in their small form so we have capitals A to Z and small letters a to z. Next we move to the Digits. The digits that are available in C are all the decimal digits from 0 to 9.White spaces now what are these White spaces via they require. When we write a program it is nothing but equivalent to writing a letter or writing a document in English.

When we write a letter we have to make it readable, there is a from section, there is a to section, there is a subject, a reference and then the body so only when it is spaced and neatly written and when there is a large document we divided into paragraphs, we give alignments we do so much only to make it more readable. So the same thing holds good when we write programs using C we have to make the program readable and legible it has to appear presentable to the user. So for this reason we have to space the statements in the program in a neat fashion so that is a reason we are provided with these facilities in this language. So a blank space is nothing but when we press a space bar we get a single space but it is always not enough when we write large programs to just leave a single space between words or sentences. We may need to leave a set of four or five spaces in between or two or three lines in between. So in order to make that feasibly we are provided with the horizontal tab and the vertical tab. The horizontal tab leaves a group of five to six spaces at a time between the previous word and the next word. That is indicated by the symbol \t. they should be in small letters we should always remember C is a case sensitive language. Capital letters and small letters are very much different in their usage in C they are not recognized as equal. All these indications of the horizontal tab and the vertical tab should be in the case in which they are given in the rules of the language. A horizontal tab leaves space in between words; vertical tab leaves space in the vertical direction that is very evident from the name itself. What is this New line. The New line is save your typing a set of statements, a set of words in a statement on a single line. When we have completed our task the cursor may not on its own move to the next line. Because the cursor is not aware of whether we wish to continue in the same line or in the next. So we have to use this New line character normally when we press the enter key when we write a program and when it has to come as a result, we have to see the output on the screen we can include this new line in C program using the symbol shown on the screen it is \n so that will take the output to be displayed to the next line. The last we have something called Form feed which was not very often used in programming languages. The Form feed is only to cause the printer to print the rest of the document on the next page. That is as soon as the compiler or the computer identifies a Form feed immediately it will led the rest of the document move to the next page and start typing the document from the next page onwards. It is used to leave the rest of the current page and start using the space available from the next page onwards. So these are the white spaces that are available in C.

Special characters: Here we are going to see the fundamentals of C programming. Before the break we had a overview of characteristics of C. stating that it is a middle- leveled language and it is a structured language. We looked into what is a program? A set of statements in a certain order comprising of symbols that are present and permitted in the language. And now we are seeing the basic elements the tokens that are available in C. because when we write programs we need to have all the information what all symbols are permitted in this software language C. so we are first seeing the character set in which we saw about the letters, the digits and the white spaces that are available in C. so lets now move over to Special characters that are available in C. From the name special characters itself we can identify that these characters have a special purpose, they have a special use in this language. There are around 30 special characters in C and each of them has a special use which cannot be identified now you may not understand because unless you write a program you may not know why it is being used in that particular place. For now it is necessary that you remember at least the most commonly used special characters so that when we are writing programs it will be easier for you to remember what are the special characters that are permitted in C? We normally use (,) - the comma, (;) - the semicolon, (:)- the colon, (_) - the underscore and slashes most often. So these are just a list of the special characters for your information. Here we are going to see the fundamentals of C programming. We had an overview of the characteristics of C stating that, it is a middle- leveled language and a structured language. We looked into what is a program? A set of statement in a certain order comprising of symbols that are present and permitted in the language. And now we are seeing the basic elements the Tokens that are available in C. Because when we write programs we need to have all the information about what all are symbols are permitted in this software language C. we have first seen the character set in which we saw about the letters, the digits and the white spaces. Now lets move over to the special characters The special characters indicate that all these characters have a special purpose when they are used in the language. So now it is better that you memorize all these special characters so that you will have an idea of what all characters are permissible in C. As we move into programming you will be able to know better why these characters have to be used in certain places and where they shouldnt be used. So the most commonly used special characters include comma, semicolon, colon, apostrophe and the slashes and we know parenthesis, square brackets and braces are all used to define arrays and functions which you will be study in detail in the future sessions. All the mathematical symbol asterisk (*), minus (-), plus (+), modulo(%) all these are other special characters which are permitted in the language. Less than and greater than symbol are for the logical and relational operation. Now lets move over to Delimiters.

Delimiters are special kind of symbols and if you will see all the delimiters that are present here are what have already been listed in the special characters. Now when we are seeing special characters I only mentioned they have a special meaning. Seven of those special characters are used as delimiters. The delimiters and their uses are given adjacent to them. So let us see the first one the colon.

A Colon is used as a label. So we all know what a label is used for it is to identify a person. When we are writing a program and when we are executing it, there is no need that we should go exactly in sequence alone, there may be a reason, there may be a necessity for us to jump to some previous point in the program. In which case there should be an indication to the compiler. I will define what a compiler is in the future sessions. There has to be an indication to the compiler so that it will know to which previous point it has to go to begin execution again. For that reason we put some label when we write a program. So when we give a label we just give an identification name followed by a colon. So the colons purpose is that whenever the compiler, the system sees a colon in the program it will immediately keep it in memory saying that this is a label so at any time in the program I may have to jump to this point so it will keep that label in memory. The next is the Semicolon- (;). There is no C program without a semicolon. Because every statement in C ends with a Semicolon. Only if there is a semicolon the compiler will consider it as a statement at all. Parenthesis-() are used in expressions that is to indicate certain symbols, certain letters in the program which have a specific meaning. Arrays are a group of variables that are stored continuously in memory so, all these we will be seeing in detail in the later sessions. Scope of statements curly braces this is again the most important delimiter in C because without this there is no programming in C. A C program begins with a brace and ends with a brace. So it indicates the scope of the program that is where it starts and where it ends. The (#)- hash symbol is used with the header files. The header files have to be included in every C program so whenever a # symbol is seen the compiler notes that there is something which it has to remember, there are some details it has to look into and get its values or get some information. So # is an indication to the compiler that it has to get information from some other place. Then you have a comma-(,) which is a variable separator all these as we start programming as we go through programs you we will be able to see what is the significance of these delimiters.

Keywords and Identifiers: Next let us look at the C keywords. Now what is meant by a keyword? A keyword is one which has already a reserved meaning. It has a fixed meaning it cannot be changed. It is reserved for a particular purpose so they have a fixed meaning and they cannot be used as variable names. A key word is similar to a symbol in C it exists as such it cannot be changed, it cannot be altered according to the users need. Its use and its purpose has been predefined by the developers of the language itself. There are certain examples, there are plenty of key words in C around 20 to 25 keywords are available in C, I just listed a few for your information. The most commonly used key words that are in C. Next we look at what are called identifiers? Now these identifiers have a number of characteristics and according to this when we write programs we can define our own identifiers in the program. First they are names of variables, functions or arrays. When we use functions, when we use variables in the program they have to be given a name because we have to identify them . Identifiers are nothing but names of variable, functions and arrays which are user defined in nature. That is when we write a program we are going to define the purpose for which the program is being written so we will know what are the variable that are needed in the program. For example if you have to calculate the area of the square the value that we need is the side so we will give such a meaning to the variable because we know that the application is to calculate the area. So we will give a variable name as area, we will give another variable say side and we will give some value so an identifier is to identify what is a value that a particular variable should hold in the program. It is a sequence of letters and digits so we can have both letters as well as digits in a mixed form as an identifier it is up to us it is our choice. Mostly lower case letters are preferred and always a letter should be the first character like we can have a5l, we cannot have 5al always a first character should be a letter later it can be a sequence of letters or digits. For example # define N 10, where N is the identifier this N is the identifier, this 10 is the value that is assigned to this identifier, this # is the special character or it is a delimiter and this define is the key word so all these # and define has a predefined meaning in C where as this N is also user defined ant this 10 is also user defined this is how we use identifiers in C.

Constants and Variables: Next we move over to constants. So what are constants? They are applicable to values that do not change during the execution of a program. So this value, the value that the constant holds is going to remain the same it cannot be changed according to the users need once you give a value to the constant it is going to hold that value till the program completes its execution and gives the result. They are classified into Numeric constants and Character constants under Numeric constants you have Integer constants and Real constants and under character constants you have Single character and String constants. Most of them you can identify from the name itself. So let us first look at the rules governing the Numeric constants. They have to be a sequence of numbers from 0 to 9. They are integers so they cannot have decimal points or fractions. They have to be whole numbers. The storage that is required for this integer constants is the minimum of two bytes and a maximum of four bytes. They can be positive or they can be negative, if no sign is mentioned it is by default taken as positive. Now these are the examples you can have -15, you can have +30, you can have simply 10. Simply 10 indicate it is a positive value. Only thing we have to remember is they have to be integer numbers they should not contain any decimals. Now we come to the concept of these real constants. The real constants are nothing but floating points. Floating points means after division there will be a reminder value and they are expressed in this exponential notation. That is they have two parts a fractional part which is also called the Mantissa and an Exponential part. Now here is an example for that we have a number 3478.12 because it has a decimal it is indicated that it is real in nature so that can be written as 3.478 *e^+3. Now there are certain rules which govern this mantissa as well as this exponential part. Now if you will see this mantissa it can be a decimal or it can be integer so here we are taking it from this number and expressing it in the form of an exponential part so you can see the difference this 3.478*e^+3 is equivalent to this number 3478.12. so this is the fractional part and this is the mantissa. The mantissa should be a real number it can either be a decimal or it can be an integer. The exponent has to be an integer you cannot have a decimal number in this part. It has to be a whole number and that e can be written either in the upper case or in the lower case. These are the rules that are governing these real constants. So they have to be floating point in nature, they need to have two parts where the mantissa can be real but a decimal or an integer, the exponent has to be an integer it can be positive or negative and you have e which can be depicted in the upper or the lower case. So these are the rules that have to be remembered when we express numbers in the real constant form.

Next we are having these character constants in this we have two types Single character and String constants. So Single character constant, they can be digits, they can be special symbol or simply a space is also a single character. But we should always remember that it should be within single quotes. Whenever the compiler sees any letter or symbol within a single quote it takes it as a character constant as a single character constant. So here I have given an example it can be a letter or a digit. Next we are having string constants. String constants where you are having sequence of character enclosed within double quotes. You are having a combination of all kinds of symbols. In a single character there is a single quote and only a single symbol inside it either a letter or a digit. In string constant you are having both letters as well as digits and they are enclosed within double quotes so that is the difference between the two. Whenever the compiler sees a single quote it takes it as a single character constant whenever you have a double quotes and letters enclosed within it takes it as string constants here again you can have letters, digits special characters and all kinds of symbols it is permitted in these character constants. Next we move to variables.Variables I have already used this term before. A variable is any name that is used to hold a value it is somewhat similar to an identifier. But these variables are most commonly used in the program as it is easier for users to use variables and give them names though they may not have any meaning in the program it is up to the users choice to define a variable that can hold a value and we can remember that a value can be changed during program execution. It has to be assigned different values at different times during program execution. Now you will see the difference here between a variable and a constant. A constant has to have a fixed value in the program which cannot be changed. A variables value can be changed during program execution and it may be declared according to the meaning of the operation. For example as I said if you are going to perform addition you can have sum as variable because the addition of two numbers is called sum. So that it up to the users choice so variables and constants are totally two different things. A constants value remain the same and variable value can be changed during program execution. Now these are the rules for defining Variables. Again they begin with characters without spaces, underscore alone is permitted and the length of the variable should be eight characters normally including the extension. I given an example here but certain versions of C permit up to 31 characters. It should not be a key word, it should not start with a digit it can be of lower case or upper case letter so all these are most commonly used so once you start using identifiers obviously the same rules almost hold good for the variables as well. So these are the Elements and Tokens in C which we have seen today. The Character set, Delimiters, Keywords, Identifiers and variables. Next we move over to the questions that are possible to be asked in these sessions.

Why is C called a middle level language? Now we have already seen a middle level is one that acts as an intermediate between the high level and the low level. So C is having those features that is understandable both to humans as well as to the system The differentiation between the interpreter and compiler? A compiler is one that converts the C program that we write into a form that the system will understand. A compiler does so with the entire program but an interpreter does it line by line that is the difference between these two. Both the compiler and the interpreter convert the program that the humans write into the object code or a form that is understandable by the system. The compiler does it all at once; the interpreter does it one by one. List the rules for declaring variables? We have already seen, it can be lower case or upper case, maximum of 31 or 8 characters, should not start with digits, it should have only letters which may have some meaning to the program What is meant by a variable and a constant? Variable is a name that can change during the execution of a program its value can change. Constant is one whose value remains the same during program execution. Delimiters are special characters with the special meaning and the uses have already given in the tabular form which you can always go through for your preparations So this is a summary of this entire session. We had an overview of C its characteristics, the Elements in C starting from the Character set to the delimiters, keywords, identifiers, constants and variables. We have seen the character set the letters, digits, the whit spaces and special characters. Identifies and variable which are used to hold values and constants whose value remain the same during the program execution and definition of this compiler and interpreter. A compiler and interpreter both of them convert the program into a form that is understandable to the system. Compiler does it all at once, the interpreter does so line by line and that is the difference between the two. So that is the basic elements of C we still have some more to cover but in this session we complete with the basic elements that are used with the program and why it is called the middle level language and why a structured language. Mrs.Shomana Gracia Jacob (EMMRC, Chennai).

Potrebbero piacerti anche