History of C Programming PDF

Summary

This document provides a history of C programming, focusing on its creation, development, and standardization. It elaborates on various applications such as operating systems, GUI development, embedded systems, compiler design, and its presence in popular software like Google Chrome.

Full Transcript

History of c programming Dennis Ritchie created C at Bell Laboratories in the early 1970s. It developed from an older language named B that Ken Thompson created. The main purpose of C's creation was to construct the Unix operating system, which was crucial in the advancement of contemporary compute...

History of c programming Dennis Ritchie created C at Bell Laboratories in the early 1970s. It developed from an older language named B that Ken Thompson created. The main purpose of C's creation was to construct the Unix operating system, which was crucial in the advancement of contemporary computers. BCPL, B, and C all fit firmly in the traditional procedural family typified by Fortran and Algol 60. BCPL, B and C differ syntactically in many details, but broadly they are similar. Development of C Programming In 1971, Dennis Ritchie started working on C, and he and other Bell Labs developers kept improving it. The language is appropriate for both system programming and application development because it was made to be straightforward, effective, and portable. Standardization of C Programming Dennis Ritchie commenced development on C in 1972 and, in collaboration with other developers at Bell Labs, proceeded to refine it. The language was developed with portability, simplicity, and efficiency in mind, rendering it applicable to both application and system programming. Applications areas of C Language The development of system software and desktop applications is mostly accomplished via the use of C programming. The following are some examples of C programming applications. Operating Systems A high-level programming language built in the C programming language was used to construct the first operating system, which was UNIX. Later on, the C programming language was used to write Microsoft Windows and several Android apps. GUI (Graphical User Interface) Since the beginning of time, Adobe Photoshop has been one of the most widely used picture editors. It was created entirely with the aid of the C programming language. Furthermore, C was used to develop Adobe Illustrator and Adobe Premiere. Embedded Systems Because it is directly related to the machine hardware, C programming is often regarded as the best choice for scripting programs and drivers for embedded systems, among other things. Google You can also use the C/C++ programming language to create the Google Chrome web browser and the Google File System. Furthermore, the Google Open Source community includes many projects that are maintained with the aid of the C/C++ programming language. Design of a Compiler You can widely use the C programming language to develop compilers, one of its most popular applications. Many other languages’ compilers were created with the connection between C and low-level languages in mind, making it easier for the machine to grasp what was being written. Many prominent compilers, such as Clang C, Bloodshed Dev-C, Apple C, and MINGW, were developed with the C programming language. Mozilla Firefox and Thunderbird Because Mozilla Firefox and Thunderbird were free and open-source email client projects, they were included here. As a result, they were developed in the C/C++ programming language. Gaming and animation Because the C programming language is based on a compiler and is thus far quicker than Python or Java, it has gained popularity in the game industry. Some of the most basic games, such as the Dino game, Tic-Tac-Toe, and the Snake game, are written in C programming languages. In addition, doom3, a first-person shooter horror game developed by id Software in 2004 for Microsoft Windows and written in C, is one of the most powerful graphics games ever created. MySQL MySQL is another open-source project that is used in relational database management systems (RDBMS). It was developed in the C/C++ programming language. Algorithm in C language An algorithm is a sequence of instructions that are carried out in a predetermined sequence in order to solve a problem or complete a work. A function is a block of code that can be called and executed from other parts of the program. A set of instructions for resolving an issue or carrying out a certain activity. In computer science, algorithms are used for a wide range of operations, from fundamental math to intricate data processing. One of the common algorithms used in C is the sorting algorithm. A sorting algorithm arranges a collection of items in a certain order, such as numerically or alphabetically. There are many sorting algorithms, each with advantages and disadvantages. The most common sorting algorithms in C are quicksort, merge, and sort. Features of the algorithm It defines several important features of the algorithm, including: o Inputs: Algorithms must receive inputs that can be represented as values or data. o Output: The algorithm should produce some output. It can be a consequence of a problem or a solution designed to solve it. o Clarity: Algorithms must be precisely defined, using unambiguous instructions that a computer or other system can follow unambiguously. o Finiteness: The algorithm requires a limited steps. It means that it should be exited after executing a certain number of commands. Basic writing of algorithms Example: - The sum of two integers. Step 1 - Get started Step 2 - Declare three integers a, b, c Step 3 - Define the values of a and b Advertisement Step 4 - Add the values of a and b Step 5 - Save the output of step 4 in c Step 6 - Print c Step 7 – Stop Flowchart:- Flowchart is a graphical representation of an algorithm. Programmers often use it as a program-planning tool to solve a problem. It makes use of symbols which are connected among them to indicate the flow of information and processing. The process of drawing a flowchart for an algorithm is known as “flowcharting”. Basic Symbols used in Flowchart Designs 1. Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic flow. A pause/halt is generally used in a program logic under some error conditions. Terminal is the first and last symbols in the flowchart. Input/Output: A parallelogram denotes any function of input/output type. Program instructions that take input from input devices and display output on output devices are indicated with parallelogram in a flowchart. Processing: A box represents arithmetic instructions. All arithmetic processes such as adding, subtracting, multiplication and division are indicated by action or process symbol. Decision Diamond symbol represents a decision point. Decision based operations such as yes/no question or true/false are indicated by diamond in flowchart. Connectors: Whenever flowchart becomes complex or it spreads over more than one page, it is useful to use connectors to avoid any confusions. It is represented by a circle. Flow lines: Flow lines indicate the exact sequence in which instructions are executed. Arrows represent the direction of flow of control and relationship among different symbols of flowchart. Rules For Creating Flowchart : A flowchart is a graphical representation of an algorithm.it should follow some rules while creating a flowchart Rule 1: Flowchart opening statement must be ‘start’ keyword. Rule 2: Flowchart ending statement must be ‘end’ keyword. Rule 3: All symbols in the flowchart must be connected with an arrow line. Rule 4: The decision symbol in the flowchart is associated with the arrow line. Advantages of Flowchart: Flowcharts are a better way of communicating the logic of the system. Flowcharts act as a guide for blueprint during program designed. Flowcharts help in debugging process. With the help of flowcharts programs can be easily analyzed. It provides better documentation. Flowcharts serve as a good proper documentation. Easy to trace errors in the software. Easy to understand. The flowchart can be reused for inconvenience in the future. It helps to provide correct logic. Disadvantages of Flowchart: It is difficult to draw flowcharts for large and complex programs. There is no standard to determine the amount of detail. Difficult to reproduce the flowcharts. It is very difficult to modify the Flowchart. Making a flowchart is costly. Some developer thinks that it is waste of time. It makes software processes low. If changes are done in software, then the flowchart must be redrawn Example : Draw a flowchart to input two numbers from the user and display the largest of two numbers Algorithm: Name of Algorithm: To add two numbers. Step 1: Start Step 2: Read two numbers as A and B Step 3: Sum = A + B Step 4: Display Sum Step 5: Stop Flowchart: Structure of the 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. Sections of the C Program There are 6 basic sections responsible for the proper execution of a program. Sections are mentioned below: 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 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 #include 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. Example: #define long long ll 4. Global Declaration 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. Example: int num = 18; 5. Main() Function 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: void main() or int main() 6. Sub Programs User-defined functions are called in this section of the program. The control of the program is shifted to the called function whenever they are called from the main or outside the main() function. These are specified as per the requirements of the programmer. Example: int sum(int x, int y) { return x+y; } Structure of C Program with example #include #include Void main() { printf("Hello, World!"); getch(); } Tokens in C A token in C can be defined as the smallest individual element of the C programming language that is meaningful to the compiler. It is the basic component of a C program. Types of Tokens in C The tokens of C language can be classified into six types based on the functions they are used to perform. The types of C tokens are as follows: 1. Keywords 2. Identifiers 3. Constants 4. Strings 5. Special Symbols 6. Operators 1. C Token – Keywords The keywords are pre-defined or reserved words in a programming language. Each keyword is meant to perform a specific function in a program. Since keywords are referred names for a compiler, they can’t be used as variable names because by doing so, we are trying to assign a new meaning to the keyword which is not allowed. You cannot redefine keywords. However, you can specify the text to be substituted for keywords before compilation by using C preprocessor directives. C language supports 32 keywords which are given below: auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while Note: The number of keywords may change depending on the version of C you are using. For example, keywords present in ANSI C are 32 while in C11, it was increased to 44. Moreover, in the latest c23, it is increased to around 54. Variable A variable in C language is the name associated with some memory location to store data of different types. There are many types of variables in C depending on the scope, storage class, lifetime, type of data they store, etc. A variable is the basic building block of a C program that can be used in expressions as a substitute in place of the value it stores. What is a variable in C? A variable in C is a memory location with some name that helps store some form of data and retrieves it when required. We can store different types of data in the variable and reuse the same variable for storing some other data any number of times. They can be viewed as the names given to the memory location so that we can refer to it without having to memorize the memory address. The size of the variable depends upon the data type it stores. C Variable Syntax The syntax to declare a variable in C specifies the name and the type of the variable. data_type variable_name = value; // defining single variable or data_type variable_name1, variable_name2; // defining multiple variable Here, data_type: Type of data that a variable can store. variable_name: Name of the variable given by the user. value: value assigned to the variable by the user. Example int var; // integer variable char a; // character variable float fff; // float variables Note: C is a strongly typed language so all the variables types must be specified before using them. Data type :- Data is the primary need for any programming language. This data can be of various types, including integers, fractional numbers, characters, and symbols, or a group of entities. To handle these different types of data, the concept of data types has been introduced in C. Data types in C, signify the characteristics of the data stored in a variable. Every type of data has its own data type that cannot be used to store other types of data. Various Data Types Primary Data Types in C Primary data types are also known as the fundamental data types because they are pre-defined or they already exist in the C language. All the other types of data types (derived and user-defined data types) are derived from these data types. Primary data types in C are of 4 types: int, char, float, and double. In this section, we are going to discuss all these data types in detail. The following table represents the memory consumed or size of each primary data types in C: DATA MEMORY RANG FORMAT TYPE (bytes) E SPECIFIER -231 to int 4 231 - %d 1 -128 to char 1 %c 127 1.2E- 38 to float 4 %f 3.4E+3 8 2.3E- 308 to double 8 %lf 1.7E+3 08 Int Data Type The int data type is used to store the integer values. Any number that falls in the range of -∞ to +∞ is said to be an integer. For example 0, 10, 105, -15, -103, etc are all integers. However, integers can be either negative or positive Syntax int variable_name; Char Data Type The char data type is used to store the characters. The characters stored in a variable of char data type have a value equivalent to its integer code. These codes are often called American Standard Code For Information Interchange or ASCII codes. The ASCII code for upper case characters A to Z starts from 65 to 90 and for lower case characters a to z, it starts from 97 to 122. The general size of a character is 1 byte. However, just like the integers the size of a char can vary according to the data type modifiers. Since all characters and symbols can be represented in their numerical ASCII value, the char type is often considered as an int type. Syntax char variable_name; Float Data Type The float data type is used to store the floating-point numbers. The numbers that have a fractional part are called floating-point numbers. For example, 3.0, 5.57, -31.2, -3.12, etc are all floating-point numbers. Moreover, it should be noticed carefully that 8 is an integer but 8.0 is a floating-point number. Although the value of both the digits is the same, 8.0 has a decimal number which differentiates it with 8. The major advantage of floating point numbers over integers is that they can represent a much larger and wider range of digits as compared to int data type. Syntax float varaible_name; Double Data Type The double data type is also used to store floating-point numbers. But still, it is considered as a distinct data type because of two reasons. The first one is that it occupies twice as much memory as type float. The second reason is that it is used to store a much larger range of floating-point numbers than a float data type. The double stores almost double the number of significant digits after the decimal point or precision of the float. However, the double data type consumes more memory and it is also slower as compared to float. So, it is advisable to use a smaller data type as much as possible for the sake of optimization of code. Syntax double variable_name; operator:- An operator is a symbol that operates on a value to perform specific mathematical or logical computations. They form the foundation of any programming language. In C++, we have built-in operators to provide the required functionality. An operator operates the operands. For example, int c = a + b; Here, ‘+’ is the addition operator. ‘a’ and ‘b’ are the operands that are being ‘added’. Operators in C++ can be classified into 6 types: 1. Arithmetic Operators 2. Relational Operators 3. Logical Operators 5. Assignment Operators 6. Ternary or Conditional Operators 1) Arithmetic Operators These operators are used to perform arithmetic or mathematical operations on the operands. For example, ‘+’ is used for addition, ‘-‘ is used for subtraction ‘*’ is used for multiplication, etc. Arithmetic Operators can be classified into 2 Types: A) Unary Operators: These operators operate or work with a single operand. For example: Increment(++) and Decrement(–) Operators. Name Symbol Description Example Increment Increases the integer value of int a = 5; ++ a++; // Operator the variable by one returns 6 Name Symbol Description Example Decrement Decreases the integer value of int a = 5; — a–; // returns Operator the variable by one 4 Example: the description Output a++ is 10 ++a is 12 b-- is 15 --b is 13 Time Complexity: O(1) Auxiliary Space : O(1) Note: ++a and a++, both are increment operators, however, both are slightly different. In ++a, the value of the variable is incremented first and then It is used in the program. In a++, the value of the variable is assigned first and then It is incremented. Similarly happens for the decrement operator. B) Binary Operators: These operators operate or work with two operands. For example: Addition(+), Subtraction(-), etc. Name Symbol Description Example int a = 3, b = 6; Addition + Adds two operands int c = a+b; // c =9 Subtracts second operand int a = 9, b = 6; Subtraction – int c = a-b; // c from the first =3 Name Symbol Description Example int a = 3, b = 6; Multiplication * Multiplies two operands int c = a*b; // c = 18 int a = 12, b = Divides first operand by the 6; Division / second operand int c = a/b; // c =2 Modulo Returns the remainder an int a = 8, b = 6; % int c = a%b; // Operation integer division c=2 2) Relational Operators These operators are used for the comparison of the values of two operands. For example, ‘>’ checks if one operand is greater than the other operand or not, etc. The result returns a Boolean value, i.e., true or false. Name Symbol Description Example int a = 3, b = 6; Is Equal To == Checks if both operands are equal a==b; // returns false int a = 3, b Checks if first operand is greater = 6; Greater Than > a>b; than the second operand // returns false Greater Than >= Checks if first operand is greater int a = 3, b Name Symbol Description Example or Equal To than or equal to the second = 6; operand a>=b; // returns false int a = 3, b Checks if first operand is lesser = 6; Less Than < a

Use Quizgecko on...
Browser
Browser