C Programming Language Introduction and History

https://krrishroytechnicalstudies.blogspot.com/?m=1

What is C programming?

C is a general-purpose programming language that is extremely popular, simple and flexible. It is machine-independent, structured programming language which is used extensively in various applications.
C was the basics language to write everything from operating systems (Windows and many others) to complex programs like the Oracle database, Git, Python interpreter and more.
It is said that 'C' is a god's programming language. One can say, C is a base for the programming. If you know 'C,' you can easily grasp the knowledge of the other programming languages that uses the concept of 'C'
It is essential to have a background in computer memory mechanisms because it is an important aspect when dealing with the C programming language.





what.c language
C language
IEEE-the best 10 top programming language in 2018

History of C language

The base or father of programming languages is 'ALGOL.' It was first introduced in 1960. 'ALGOL' was used on a large basis in European countries. 'ALGOL' introduced the concept of structured programming to the developer community. In 1967, a new computer programming language was announced called as 'BCPL' which stands for Basic Combined Programming Language. BCPL was designed and developed by Martin Richards, especially for writing system software. This was the era of programming languages. Just after three years, in 1970 a new programming language called 'B' was introduced by Ken Thompson that contained multiple features of 'BCPL.' This programming language was created using UNIX operating system at AT&T and Bell Laboratories. Both the 'BCPL' and 'B' were system programming languages.
father of C language
father of C language
In 1972, a great computer scientist Dennis Ritchie created a new programming language called 'C' at the Bell Laboratories. It was created from 'ALGOL', 'BCPL' and 'B' programming languages. 'C' programming language contains all the features of these languages and many more additional concepts that make it unique from other languages.
'C' is a powerful programming language which is strongly associated with the UNIX operating system. Even most of the UNIX operating system is coded in 'C'. Initially 'C' programming was limited to the UNIX operating system, but as it started spreading around the world, it became commercial, and many compilers were released for cross-platform systems. Today 'C' runs under a variety of operating systems and hardware platforms. As it started evolving many different versions of the language were released. At times it became difficult for the developers to keep up with the latest version as the systems were running under the older versions. To assure that 'C' language will remain standard, American National Standards Institute (ANSI) defined a commercial standard for 'C' language in 1989. Later, it was approved by the International Standards Organization (ISO) in 1990. 'C' programming language is also called as 'ANSI C'.





C language
c language
History of C
Languages such as C++/Java are developed from 'C'. These languages are widely used in various technologies. Thus, 'C' forms a base for many other languages that are currently in use.

Where is C used? Key Applications

  1. 'C' language is widely used in embedded systems.
  2. It is used for developing system applications.
  3. It is widely used for developing desktop applications.
  4. Most of the applications by Adobe are developed using 'C' programming language.
  5. It is used for developing browsers and their extensions. Google's Chromium is built using 'C' programming language.
  6. It is used to develop databases. MySQL is the most popular database software which is built using 'C'.
  7. It is used in developing an operating system. Operating systems such as Apple's OS X, Microsoft's Windows, and Symbian are developed using 'C' language. It is used for developing desktop as well as mobile phone's operating system.
  8. It is used for compiler production.
  9. It is widely used in IOT applications.

Why learn 'C'?

As we studied earlier, 'C' is a base language for many programming languages. So, learning 'C' as the main language will play an important role while studying other programming languages. It shares the same concepts such as data types, operators, control statements and many more. 'C' can be used widely in various applications. It is a simple language and provides faster execution. There are many jobs available for a 'C' developer in the current market.
'C' is a structured programming language in which program is divided into various modules. Each module can be written separately and together it forms a single 'C' program. This structure makes it easy for testing, maintaining and debugging processes.
'C' contains 32 keywords, various data types and a set of powerful built-in functions that make programming very efficient.
Another feature of 'C' programming is that it can extend itself. A 'C' program contains various functions which are part of a library. We can add our features and functions to the library. We can access and use these functions anytime we want in our program. This feature makes it simple while working with complex programming.
Various compilers are available in the market that can be used for executing programs written in this language.
It is a highly portable language which means programs written in 'C' language can run on other machines. This feature is essential if we wish to use or execute the code on another computer.

How 'C' Works?

C is a compiled language. A compiler is a special tool that compiles the program and converts it into the object file which is machine readable. After the compilation process, the linker will combine different object files and creates a single executable file to run the program. The following diagram shows the execution of a 'C' program
https://krrishroytechnicalstudies.blogspot.com/
https://krrishroytechnicalstudies.blogspot.com/C language
Nowadays, various compilers are available online, and you can use any of those compilers. The functionality will never differ and most of the compilers will provide the features required to execute both 'C' and 'C++' programs.
Following is the list of popular compilers available online:
  • Clang compiler
  • MinGW compiler (Minimalist GNU for Windows)
  • Portable 'C' compiler
  • Turbo C

Summary

  • 'C' was developed by Dennis Ritchie in 1972.
  • It is a robust language.
  • It is a low programming level language close to machine language
  • It is widely used in the software development field.
  • It is a procedure and structure oriented language.
  • It has the full support of various operating systems and hardware platforms.
  • Many compilers are available for executing programs written in 'C'.
  • A compiler compiles the source file and generates an object file.
  • A linker links all the object files together and creates one executable file.
  • It is highly portable.

     
   
In this tutorial, we will learn to install C in Windows, Mac, and Linux.

Install C on Windows

We will use an open-source Integrated Development environment named Code::Blocks which bundles a compiler (named gcc offered by Free Software Foundation GNU), editor and debugger in a neat package.
Step 1) Go to http://www.codeblocks.org/downloads and click Binary Release.
c language https://krrishroytechnicalstudies.blogspot.com/
Step 2) Choose the installer with GCC Compiler, e.g., codeblocks-17.12mingw-setup.exe which includes MinGW's GNU GCC compiler and GNU GDB debugger with Code::Blocks source files.
Step 3) Run the downloaded installer and accept the default options.
Add caption
Step 4) Accept the Agreement
Step 5) Keep the component selection default and click Next.
c language 
Step 6) You may change the installation folder and click Next.
c language\
Step 7) To launch Code::Blocks double click on the icon.
Step 8) It will detect the gcc compiler automatically, set it as default.
https://krrishroytechnicalstudies.blogspot.com/
c language
Associate C/C++ files with code::blocks
Step 9) You will see the IDE Home screen.
https://krrishroytechnicalstudies.blogspot.com/
c language

Install C in Linux

Linux operating systems mostly comes with GCC preinstalled. To verify if the compiler is installed on the machine, run the following command in the terminal:
gcc --version
After executing this command if the gcc is installed on the machine then it will return the information about the compiler otherwise it will ask you to install the compiler.
To set up the 'C' environment on Linux distributions follow the given steps:
1. Open terminal.
2. For red-hat, Fedora users, type and execute this command
# yum groupinstall 'Development Tools'
3. For Debian and Ubuntu users, type and execute following command
$ sudo apt-get update
$ sudo apt-get install build-essential manpages-dev
4. To verify that the GCC has been successfully installed on the machine as we discussed earlier, execute the following command
gcc --version

Install C on MAC

To set up a 'C' programming environment on MAC operating system, follow the given steps:
1. Visit the given link https://developer.apple.com/downloads/index.action and download. You will need an Apple developer ID
"Command Line Tools for X-Code," pick any version (latest version is always recommended) and download the .dmg file.
2. After the file is being downloaded on the machine, double click and follow the wizard and install the file. Always keep the default settings as suggested by the installation wizard.
3. After the installation process, open a terminal and run gcc -v command to check if everything is successfully installed.

Conclusion:

'C' program can be written and executed on any machine that has a suitable environment to run the program. Its recommended using an IDE to run C programs. An IDE includes a compiler, editor and debugger. Clanfg, MinGW compiler (Minimalist GNU for Windows), Portable 'C' compiler, Turbo C are popular compilers available.


 
Here, is a Hello World program in C
#include<stdio.h> //Pre-processor directive
void main()  //main function declaration
{
printf("Hello World"); //to output the string on a display
getch ();  //terminating function
}
Here is the code explanation:

Pre-processor directive

#include is a pre-processor directive in 'C.'
#include <stdio.h>, stdio is the library where the function printf is defined. printf is used for generating output. Before using this function, we have to first include the required file, also known as a header file (.h).
You can also create your own functions, group them in header files and declare them at the top of the program to use them. To include a file in a program, use pre-processor directive
#include <file-name>.h
File-name is the name of a file in which the functions are stored. Pre-processor directives are always placed at the beginning of the program.

The main function

The main function is a part of every 'C' program. We can represent the main function in various forms, such as:
  • main()
  • int main()
  • void main()
  • main(void)
  • void main(void)
  • int main(void)
The empty parentheses indicate that this function does not take any argument, value or a parameter. You can also represent this explicitly by placing the keyword void inside the parentheses. The keyword void means the function does not return any value, in this case, the last statement is always getch ().
#include<stdio.h> //Pre-processor directive
int main()  //main function declaration
{
printf("Hello World"); //to output the string on a display
return 0;  //terminating function
}
In the above example, the keyword int means the function will return an integer value. In this case, the last statement should always return 0.

The source code

After the main function has been declared, we have to specify the opening and closing parentheses. Curly brackets { }, indicate the starting and end of a program. These brackets must be always put after the main function. All the program code is written inside these brackets, such as declarative and executable part.
The printf function generates the output by passing the text "Hello World!"
The semicolon ; determines the end of the statement. In C, each statement must end with a semicolon.
So we have successfully installed the compiler and now can begin working in 'C.' We will write a simple program that will say hello to us. Let's start.

How to run C Program

Step 1) Create a new Project
C program
 c program
Step 2) In the pop-up,
  1. Select File
  2. Choose the "C/C++ Source"
  3. Click "Go."
https://krrishroytechnicalstudies.blogspot.com/
c program
Step 3) Continue, by clicking on "Next."
https://krrishroytechnicalstudies.blogspot.com/
 c program
Step 4) To create the new file ,select a "C" file then click on "Next" button to continue.
Step 5) Set the file path by clicking the "..." button, the explorer window permits to create the C file.
Step 6) Select the path of your new C File then its name which has .c extension and save it.
C programming
hello wold file
Step 7) Finally, to confirm the C file creation click "Finish."
C programming
c programming
Step 8) Enter the code, save it and compile it by clicking on the "Build & Run "button.
 https://krrishroytechnicalstudies.blogspot.com/
c program
Here is the result:
 Hello, World! 

Summary

  • The main function is a mandatory part of every 'C' program.
  • To use the functionality of a header file, we have to include the file at the beginning of our program.
  • Every 'C' program follows a basic structure.
c language


What Is Comment In C Language?

A comment is an explanation or description of the source code of the program. It helps a developer explain logic of the code and improves program readability. At run-time, a comment is ignored by the compiler.
There are two types of comments in C:
1) A comment that starts with a slash asterisk /* and finishes with an asterisk slash */ and you can place it anywhere in your code, on the same line or several lines.
2) Single-line Comments which uses a double slash // dedicated to comment single lines

Example Single Line Comment

// single line comment example
Here is an example of comments type
// C program to demo 
// Single Line comment 
#include <stdio.h> 
int main(void) 
{ 
  
 // This is a single line comment 
 printf("Guru99"); 
 return 0;  // return zero
}

Example Multi Line Comment

/* Sample Multiline Comment
Line 1
Line 2
….
…
*/
Example Single Line Comment
#include <stdio.h>
int main() {
/* in main function
I can write my principal code
And this in several comments line /*
int x = 42; //x is a integer variable
printf("%d", x);
return 0;} 

Why do you need comments?

A good programmer who writes codes understood by a human is better than a programmer who generates codes understood only by the machine.
So, it is highly recommended to insert comments to your code because it is good programming practice. Comments do not affect a program because the compiler ignores them.
Comments help the developer understand the logic/algorithm of the code if he revisits it after a long time.

    

Comments