Skip to main content

Classification of Languages


FIGURE 1.11 Inventors of various programming languages

C Language

What about the name? Why it was named C, why not something else. The C language is so named because its predecessor was called B. The B language was developed by Ken Thompson of Bell Labs.

C is a programming language which born at “AT & T’s Bell Laboratories” of USA in 1972. It was written by Dennis Ritchie. This language was created for a specific purpose: to design the UNIX operating system (which is used on many computers). From the beginning, C was intended to be useful-to allow busy programmers to get things done.

Because C is such a powerful language, its use quickly spread beyond Bell Labs. In the late 70’s C began to replace widespread well-known languages of that time like PL/I, ALGOL etc. Programmers everywhere began using it to write all kinds of programs. Soon, however, different organizations began applying their own versions of C with a subtle difference. This posed a serious problem for system developers. To solve this problem, the American National Standards Institute (ANSI) formed a committee in 1983 to establish a standard definition of C. This committee approved a version of C in 1989 which is known as ANSI C. With few exceptions, every modern C compiler has the ability to adhere to this standard. ANSI C was then approved by the International Standards Organization (ISO) in 1990.

Example:

To understand the working and the processes involved in C programs, let us take an example. Suppose we want to calculate the average of the marks in three subjects. We may use the following formula for this:



The same calculation can be done with the help of program. Let us write a C program for calculating average. The program will be as follows:

Program 1:


/* First Program in C */
#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
float marks1, marks2, marks3, average;
printf(“\n Enter the marks of three subjects “);
scanf(“%f%f%f”,&marks1,&marks2,&marks3);
average = (marks1 + marks2 + marks3) / 3;
printf(“ Average marks of three subjects are %f”,average);
getch();
}



Understanding the program:

// First Program in C

The two forward slash (//) tells to the compiler that whatever follows after slash, don’t compile. Comments are very much useful because if you have written program today, than you might forget after one year that for what the program is written. It also helps to modify the program.

#include<stdio.h>

<stdio>stands for Standard Input Output. #include<stdio.h> tells the compiler to include a header file named stdio.h in the program. Header file in C is nothing but collection of various functions. This line adds the contents of file stdio.hto the source program. After including this file you can use its functions like printf(), scanf() etc.

#include<conio.h>

<conio>stands for Console Input Output. This line adds the contents of file conio.hto the source program. We are using the getch() function in our program and this function is declared in conio.h.

void main()

Every program must have a main() because program starts execution from this function. But what does the keyword void means before the main(). This means that main function will not return any value to the compiler.

{

Starts the main program.

clrscr();

clrscr() stands for Clear Screen. The clrscr() clears the output screen means any output shown by previously run program will be erased and that’s why we always put them at the beginning. (;) semi-colon indicates the end of statement.

float marks1, marks2, marks3, average;

floatis a keyword and cannot be used as a variable. Here four variables are declared of float type named marks1, marks2, marks3, and average. Variables are used to store data or information; and could be defined according to our needs. In this case we have to store a number, which could be a decimal. Hence, we have declared the variable to be of float type, which can store decimal value.

printf(“\n Enter the marks of three subjects “);

It is known as output function. printf() function is defined in the stdio.hheader file. This function prints a series of characters and values on the screen. In this case it prints;Enter the marks of three subjectson the screen. The symbol (\n) is used to display a new line. The text following will be displayed in a new line.

scanf(“%f%f%f”,&marks1,&marks2,&marks3);

It is known as input function. scanf() function is used to read the data. In this case, scanf() function accepts three subject marks that you enter, and stores them in the variables named marks1, marks2, and marks3.

average = (marks1 + marks2 + marks3) / 3;

In this line we are calculating the average value by adding all three marks and dividing the result by 3. After getting the average, it is stored in the variable named average.

printf(“ Average marks of three subjects are %f”,average);

In this line, we are displaying the average of the marks in three subjects which is stored in the variable average. The symbol, %f, both in the case of scanfand printf, simply lets the compiler know that the value being read in, or printed out, is a float value.

getch();

In this line, we are using the getch() function to read a key from the keyboard. If this function is not used, the program will stop shortly after calculating the average marks. To display the average on the screen until the user presses any key to terminate the application, we use the getch() function. The getch() function is declared in the header file, conio.h.

}

This is the closing brace which ends the main program.


Advantages of C language

·         Program written in c is very efficient and fast. This is due to its variety of data types and powerful operators. It is many time faster than BASIC. This helps developers in saving their valuable time.

·         C is a powerful and flexible language which helps system developers to deliver various complex tasks with ease. C is used for diverse projects as operating systems, word processors, graphics, spreadsheets, and even compilers for other languages.

·         C is highly portable language. This means that a program written in C for one computer system can be run on another system with little or no modification.

·         Functions can be reused in other applications or programs by passing pieces of information to the functions, you can create useful, reusable code.

·         Writing C program with user-defined functions makes program more simple and easy to understand. Breaking a problem into small parts (known as functions) makes program debugging, maintenance and testing easier.


Disadvantages of C language

·         There is no runtime checking.
·         There is no strict type checking (for ex: we can pass an integer value for the floating data type).
·         As program grows in size, it becomes difficult to find errors.
·         No automatic garbage collection (means unused memory cannot be used again).
·         No nested function definitions.
·         The greatest disadvantage of this language is poor memory management.



C ++ Language

If there is a language by which most of the applications can be created than why there is a need of another language? Answer to this question is, as program size increases, managing programs becomes very difficult. So to remove this disadvantage from previous languages like ALGOL, BASIC and C, C++ (C and increment operators (++)) was invented.

C++ is a general purpose programming language invented in the early 1980s by BjarneStroustrup at Bell Labs. It is similar to C, invented in the early 1970s by Dennis Ritchie, but is safer language than C and includes modern programming techniques such as object oriented programming.

In fact C++ was originally called C with Classes and is so compatible with C that it will probably compile more than 99% of C programs without changing a line of source code. The language began as enhancements to C, first adding classes, then virtual functions, operator overloading, multiple inheritance, templates, and exception handling among other features.

As one of the most popular object oriented programming languages ever created, C++ is widely used in software development industry. Some of its applications include system software, application software, device drivers, embedded software and entertainment software such as video games. C++ is also used for hardware design, where design is initially described in C++, then analyzed, architecturally constrained, and scheduled to create a register transfer hardware description language via high level synthesis.

Example:

To understand the working and the processes involved in C++ programs, let us take an example. We will take same example that we had taken in C language, because to compare both the programs.





// First Program
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
float marks1, marks2, marks3, average;
cout<< “ Enter the three subjects marks”;
cin>> marks1 >> marks2 >> marks3;
average = (marks1 + marks2 + marks3) / 3;
cout<< “ Average is “ << average;
getch();
}

Understanding the program

Here only four lines are different than program written in C language and they are:

#include<iostream.h>

<iostream>stands for input output stream. It is a header file which includes objects like coutand cin.

cout<< “ Enter the three subjects marks”;

coutis an output stream. It stands for console output. It acts same as printf() in C language. << is an insertion operator which inserts one by one character into stream.

cin>> marks1 >> marks2 >> marks3;

cinis an input stream. cinstands for console input.It acts same as scanf() in C language. >> is extraction operator which extracts one by one character and gives to processor for processing.

cout<< “ Average is “ << average;

It is a statement which will display an average of marks.





FIGURE 1.12 Internal working of C++ program


Explanation of above diagram:

We know that to get information from computer we need to input some data. Here data is entered through keyboard and it is passed to input stream (stream means collection of characters) and each character is extracted by process one by one from input stream and it starts processing. After processing, processer sends data to the output streamand output is received by monitor. As per above example, through cinobject we pass data and with the help of coutobject we receive information.


Advantages of C++ Language

·         Program code can be reused again, so less time in developing any application.
·         Data can be secured.
·         Same function name can be used again with the help of polymorphism.
·         You can acquire the properties of object of another class.


Disadvantages of C++ Language

·         It is not pure object oriented language.
·         Not platform independent (means program written for windows cannot be run on Mac 0S).
·         Does not provide efficient means of garbage collection.
·         Gets complex when you want to develop a graphics rich application.
·         It creates .obj format after compiling so it is easy to be hacked.



Made By: Chaudhary Amit V.

Comments

Popular posts from this blog

Characteristics of a Good Programming Language

Till now there are many high level languages which are very popular, and there are others, which could not become so popular in-spite of being very powerful. There might be many reasons for the success of a language, but one obvious reason is the characteristics of the language. Several characteristics believed to be important with respect to making a programming language good are briefly discussed below. Simplicity A good programming language must be simple and easy to learn and use. For example, BASIC is liked by many programmers only because of its simplicity. Thus, a good programming language should provide a programmer with a clear, simple and unified set of concepts which can be easily grasped. It is also easy to develop and implement a compiler or an interpreter for a programming language that is simple. However, the power needed for the language should not be sacrificed for simplicity. The overall simplicity of a programming language strongly affects the readability of the pr...

Angular 4 and Firebase Authentication: Email/Password

In our  previous  article we saw how to create authentication module using Google identity provider. Now we will see how to implement Email and Password authentication using Firebase. We will use Bootstrap form to create intuitive user interface for sign-up and login using Email and Password. Step 1: Create signUp component. ng generate component signUp Step 2: Create custom form in sign-up.component.html file. The result of above code: Step 3: Add two functions for creating the user and login using Email and Password in src/app/providers/AFAuth.ts file. Step 4: Call createUserWithEmailAndPassword function in service from sign-up.component.ts. Step 5: Update routing configuration in app.module.ts  to include signUp component. Step 6: Update Login form to have Bootstrap form. The result of the above code. Step 7: Enable Email/Password component in Firebas...

Angular 4 and Firebase Authentication: Setup

If you have come to this article, it means you are keen to learn new technology and that too Firebase. I love Firebase because it provides all basic but important features of any web application. Take for example, authentication, which is cumbersome and risky if not implemented with utmost care. And when we have the integration of Angular and Firebase, it becomes a lot easier for a developer to build such crucial modules in less time with minimal efforts. In this article we will create a simple Angular application using Firebase. I am going ahead with the understanding that you know the benefits of Firebase and have little knowledge about it. There are plenty of posts out on the web if you are behind. Step 1: Install Angular CLI (if not installed). npm install -g angular-cli Step 2: Create new Angular 4 project. By default now angular CLI will create Angular 4 project so you need not fret. ng new firebase-authentication Step 3: Check whether the ne...