Menu Bar

Introduction to C programming

What is C?:

C is a procedural programming language. It was initially developed by Dennis Ritchie between 1969 and 1973. It was mainly developed as a system programming language to write operating system. The main features of C language include low-level access to memory, simple set of keywords and clean style  these features make C language suitable for system programming like operating system or compiler development.



Structure of C programming:

Header                          #include<stdio.h>
Main()                            int main(){
Variable declaration            int a=10;
Body                                   printf("%d", a);
Return                                return 0; }



Pro's:

1. Portable language: The C programs written in one computer can run on any computer without any change of the program code or having a slight change.

2. Building block for other language: The C program act as the building block for other programming language. Programs written in C are more efficient and easy to understand.

3. Structured programming language: C program is a procedure-oriented language with a collection of function modules and blocks that form a complete program. The structured blocks make it easy to debug, test and maintain the program.

4. Easy to learn: It is very easy to learn the C language and acts as the basic for understanding other complex languages. It uses syntax similar to the English language for easy understanding.



Con's:

1. Data security: There is a lot of  buffer overflow in C language and this can lead to overwriting information in the memory. When pointers are updated with the incorrect data, it will result in memory corruption.

2. No run-time checking: The C language does not allow run-time checking making it difficult to fix the bugs if you extend the program. Mostly it does compile type checking.

3. No code reuse: C language doesn't have oop features which support source code re-usability. It doesn't support constructors and destructors.

4. Namespace concept: C language doesn't support program namespace thus, it is impossible to declare two variables at the same time like in the C++ program.



Editors to write C:

There are several text editors out there that  programmers use to write C code, but IDE have come up to offer comprehensive facilities and components for easy and ideal programming. Some of those IDEs are
1. Turbo C
2. Dev C++
3. Netbeans
4. Eclipse
5. Code blocks



What is a compiler?

A compiler is a computer program or set of programs that transforms source code written in a high level programming language into a low level programming language i.e. binary code or machine language.



Download and install compiler:





Check whether compiler is installed or not( using cmd ):





Write a C program to display hello world:





Compile C program using command prompt:





Run object code file:





Rename object code while generating:





Run after rename the object code file:





Interpreter:

An interpreter is a computer program that is used to directly execute program instructions written using one of the many high level programming languages. The interpreter transforms the high level program into an intermediate language that it then executes, or it could parse the high level source code and then performs the commands directly, which is done line by line or statement by statement.



Stdio.h:

The C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header <stdio.h>.
Some of the C inbuilt functions which are declared in stdio.h header file are:
1. printf(): Print character, string, float, integer, octal and hexadecimal values.
2. scanf(): Read a character, string, numeric data.
3. getc(): Reads character from file.
4. gets(): Reads line from keyboard.
5. getchar(): Reads character from keyboard.
6. puts(): Writes line to output screen.
7. putchar(): Writes a character to screen.
8. putc(): Writes a character to file.



Parts of C program:

1. Pre-processor
2. Header file
3. Function
4. Variable
5. Statement
6. Comments



After include parts of C program to hello world file: