User:Amaansid0627/sandbox

Overview of C
Language C is a structured programming language developed by Dennis Ritchie in 1973 at Bell Laboratories. It is one of the most popular computer languages today because of its structure, high-level abstraction, machine independent feature etc. C language was developed to write the UNIX operating system, hence it is strongly associated with UNIX, which is one of the most popular network operating system in use today and heart of internet data superhighway.

In the video below we have covered the complete introduction to the C language. If you want you can skip the video, as the concepts are covered in the topics below.

History of C language C language has evolved from three different structured language ALGOL, BCPL and B Language. It uses many concepts from these languages while introduced many new concepts such as datatypes, struct, pointer etc. In 1988, the language was formalised by American National Standard Institute(ANSI). In 1990, a version of C language was approved by the International Standard Organisation(ISO) and that version of C is also referred to as C89.

Evolution of c language

The idea behind creating C language was to create an easy language which requires a simple compiler and enables programmers to efficiently interact with the machine/system, just like machine instructions.

C language compiler converts the readable C language program into machine instruction.

Why C Language is so popular? C language is a very good language to introduce yourself to the programming world, as it is a simple procedural language which is capable of doing wonders.

Programs written in C language takes very less time to execute and almost executes at the speed of assembly language instructions.

Initially C language was mainly used for writing system level programs, like designing operating systems, but there are other applications as well which can be very well designed and developed using C language, like Text Editors, Compilers, Network Drivers etc.

Latest Version of C The current latest version of C language is C11, which was introduced in 2011. It is supported by all the standard C language compilers.

Many new features have been introduced in this version and an overall attempt to improve compatibility of the C language with C++ language has been made. We will learn about the C11 edition, once we are done with learning C language, towards the end of this tutorial series.

Features of C language
It is a robust language with rich set of built-in functions and operators that can be used to write any complex program. The C compiler combines the capabilities of an assembly language with features of a high-level language. Programs Written in C are efficient and fast. This is due to its variety of data type and powerful operators. It is many time faster than BASIC. C is highly portable this means that programs once written can be run on another machines with little or no modification. Another important feature of C program, is its ability to extend itself. A C program is basically a collection of functions that are supported by C library. We can also create our own function and add it to C library. C language is the most widely used language in operating systems and embedded system development today. features of C language C Language is an amazing language when it comes to simplicity of syntax with decent functionality. It is a perfect mix of both, which makes it the best contender to be taught to students who have just started learning coding, to introduce them into the programming world.

First C Program and its Structure
Lets see how to write a simple and most basic C program:

''#include  int main { printf("Hello,World"); //single line comment return 0; /*   multi line comments /* } '' Hello,World

Different parts of C program Pre-processor Header file Function Variables Statements & expressions Comments All these are essential parts of a C language program.

Pre-processor
 * 1) include is the first word of any C program. It is also known as a pre-processor. The task of a pre-processor is to initialize the environment of the program, i.e to link the program with the header files required.

So, when we say #include , it is to inform the compiler to include the stdio.h header file to the program before executing it.

Header file A Header file is a collection of built-in(readymade) functions, which we can directly use in our program. Header files contain definitions of the functions which can be incorporated into any C program by using pre-processor #include statement with the header file. Standard header files are provided with each compiler, and covers a range of areas like string handling, mathematical functions, data conversion, printing and reading of variables.

With time, you will have a clear picture of what header files are, as of now consider as a readymade piece of function which comes packaged with the C language and you can use them without worrying about how they work, all you have to do is include the header file in your program.

To use any of the standard functions, the appropriate header file must be included. This is done at the beginning of the C source file.

For example, to use the printf function in a program, which is used to display anything on the screen, the line #include  is required because the header file stdio.h contains the printf function. All header files will have an extension .h

main function main function is a function that must be there in every C program. Everything inside this function in a C program will be executed. In the above example, int written before the main function is the return type of main function. we will discuss about it in detail later. The curly braces { } just after the main function encloses the body of main function.

We will learn what functions are in upcoming tutorials.

CommentsItalic text We can add comments in our program to describe what we are doing in the program. These comments are ignored by the compiler and are not executed.

To add a single line comment, start it by adding two forward slashses // followed by the comment.

To add multiline comment, enclode it between /* .... */, just like in the program above.

Return statement - return 0; A return statement is just meant to define the end of any C program.

All the C programs can be written and edited in normal text editors like Notepad or Notepad++ and must be saved with a file name with extension as .c

If you do not add the extension .c then the compiler will not recognise it as a C language program file.

Writing your first C Program In the video below we have explained stepwise how to write your first C program, compile it and run it.

Compile and Run C Program
To compile and run a C language program, you need a C compiler. To setup a C language compiler in your Computer/laptop, there are two ways:

Download a full fledged IDE like Turbo C or Microsoft Visual C++, which comes along with a C language compiler. Or, you use any text editor to edit the program files and download the C compiler separately. Here we have a simple video, explaining how to setup Tubrbo C/C++ for writing, compiling and running C programs.

Using an IDE - Turbo C We will recommend you to use Turbo C IDE, oldest IDE for c programming. It is freely available over internet and is good for a beginner.

Step 1 : Open turbo C IDE(Integrated Development Environment), click on File and then click on New

first c program with turbo C Step 2 : Write the above example as it is

Write a C program with turbo C Step 3 : Click on compile or press Alt+f9 to compile the code

Compiling a C program with turbo C Step 4 : Click on Run or press Ctrl+f9 to run the code

Running a C program with turbo C Step 5 : Output

Output of C program with turbo C Without an IDE If you do not wish to setup an IDE and prefer the old school way, then download the C compiler which is called gcc from the gcc website https://gcc.gnu.org/install/

Once you have downloaded and installed the gcc compiler, all you have to do it, open any text editor, copy and paste the C program code from the previous tutorial, and save it with the name hello.c

Open Command prompt or Terminal(if you use Ubunut or Mac OS), and go to the directory where you have saved the hello.c program file.

Type the command gcc hello.c to compile the code. This will compile the code, and if there are no errors then it will produce an output file with name a.out(default name)

Now, to run the program, type in ./a.out and you will see Hello, World displayed on your screen.

$ gcc hello.c $ ./a.out

Hello,World

Difference between Compile and Run You must be thinking why it is a 2 step process, first we compile the code and then we run the code. So, compilation is the process where the compiler checks whether the program is correct syntax wise, and there are no errors in the syntax.

When we run a compiled program, then it actually executes the statements inside the main function.

C Language Basic Syntax Rules
C language syntax specify rules for sequence of characters to be written in C language. In simple language it states how to form statements in a C language program - How should the line of code start, how it should end, where to use double quotes, where to use curly brackets etc.

The rule specify how the character sequence will be grouped together, to form tokens. A smallest individual unit in C program is known as C Token. Tokens are either keywords, identifiers, constants, variables or any symbol which has some meaning in C language. A C program can also be called as a collection of various tokens.

In the following program,

int main {   printf("Hello,World"); return 0; } if we take any one statement:
 * 1) include

printf("Hello,World"); Then the tokens in this statement are→ printf, (, "Hello,World", ) and ;.

So C tokens are basically the building blocks of a C program.

Semicolon ; Semicolon ; is used to mark the end of a statement and beginning of another statement. Absence of semicolon at the end of any statement, will mislead the compiler to think that this statement is not yet finished and it will add the next consecutive statement after it, which may lead to compilation(syntax) error.

int main {   printf("Hello,World") return 0; } In the above program, we have omitted the semicolon from the printf("...") statement, hence the compiler will think that starting from printf uptill the semicolon after return 0 statement, is a single statement and this will lead to compilation error.
 * 1) include

Comments Comments are plain simple text in a C program that are not compiled by the compiler. We write comments for better understanding of the program. Though writing comments is not compulsory, but it is recommended to make your program more descriptive. It make the code more readable.

There are two ways in which we can write comments.

Using // This is used to write a single line comment. Using /* */: The statements enclosed within /* and */, are used to write multi-line comments. Example of comments :

// This is a comment

/* This is a comment */

/* This is a long and valid comment */

// this is not a valid comment Some basic syntax rule for C program C is a case sensitive language so all C instructions must be written in lower case letter. All C statement must end with a semicolon. Whitespace is used in C to describe blanks and tabs. Whitespace is required between keywords and identifiers. We will learn about keywords and identifiers in the next tutorial.