Introduction to C Programming
Basics Of C Programming C Programming Crash Course Go From Zero To Hero in C

Introduction to C Programming

You might be wondering why Introduction to C Programming is important. Why not directly jump to writing c programs.

Well, this article on Introduction to C Programming is very important to learn. I strongly recommend reading this before jumping to programming. Because it will help you to understand several important processes. For instance, memory allocation, the working process of different hardware. And all these things will help you in cracking interview easily or to become a pro developer.

Getting Started

Don’t Skip : Before writing serious programs in C, it would be interesting to know what really is C (introduction to C Programming), how it came into existence and why it is called as mother of programming language. Hey smarty, We will go from very basic to advance so that your friends can also follow this article easily.

What is a Computer?

A computer is an electronic gadget that takes input from the user, process that input and gives output. Laptops, Desktop computers, mobile phone, Digital watch, Digital camera, etc are also computers as they work on given input however their capabilities differ. You might be asking this is too basic however there is connectivity read below.

Does zero or one exist inside a computer?

Well, there is no physical significance of 0 and 1 inside the computer. These are just representation of two states of voltage in digital circuits, the high voltage is represented with 1 and low voltage with 0.

Why understand 0 and 1 fundamentals?

Computers understand only binary language which is represented in the form of 0 and 1. Computers are just a machine that can work on our instruction. But, we can’t say “Computer! Please print my name on screen”. Yeah, if we can!

A computer can’t work in the above situation as it doesn’t understand our language. Just assume computers as aliens which understand only the language of 0 and 1.

Program is a set of instructions to perform a specific task. Running a program instruction is called process.

Why Learn C Language?

Instead of being one of the oldest programming languages, C is not dead yet. In these days also C language is very popular because of its reliability, simplicity, easy to use features.

There are many opinions that are often heard today is – “C has been superseded by other programming languages like C++, C#, and Java”. However, in my opinion, there are many reasons for learning the C language.

Let us see few reasons one by one. 

  • Major parts of famous working frameworks and operating systems like Windows, UNIX, Linux, and Android are written in C. Even today when performance (speed of execution) is considered, C becomes primary choice of programmers. 
  • Mobile devices like smartphones and tablets have become very popular today. Also common devices like the washing machine, microwaves are getting smarter by the day. This smartness comes from a microprocessor.  These programmes need to run fast as well as they need to work in a constrained measure of memory. For your kind information, these programs are written in C.
  • Let us take the example of a video game. Just assume if you are firing a bullet and bullet hits the target after a delay of 10 sec. Will you play that game? Never! Because of speed as speed matters for you. 
  • Therefore to match the expectation of the player the game has to respond fast to the user inputs. In this situation, C language scores over other languages. As a result of this many popular gaming frameworks, for instance, DirectX and gaming engine like Allegro have been built in C language.
  • In addition, if it comes to interaction with hardware devices, C is the best choice of programmers as c provides several elements that make this interaction feasible without compromising performance.

How to name a C Program?

Any program that you gonna write will have some name along with the extension. You know how a music file is saved in your machine, it has a file name like rocking and extension say mp3. And file name and extension is separated by a dot (.) operator like rocking.mp3.

Similarly, you will name a file, then put a dot over there, write c after that like rocking.c.

However, this is not the final software that you will either give to your clients or show to your friends. After a successful compile, you will get an executable file (.exe) and that will be your final software. So, you can enjoy your software without seeing your code.

Have You enjoyed the article on Introduction to C Programming!

How a C Program executes?

It is important to discuss how a C Program executes. As a result, it will help you to understand memory allocation, the working process of different hardware. In addition, all these things will help you in cracking interview easily or to become a pro developer.

Important Points In Execution Of C Program

  • C Program file is stored somewhere in the hard disk of your system.
  • Whenever we click on it to run this program. The click event is listened by the operating system and loads this file from hard disk to RAM (Random Access Memory) using loader (a dedicated program to load content to RAM).
  • RAM is a type of primary memory which is volatile in nature, this means that nothing can reside permanently in RAM.
  • RAM contains only those programs which are active at a particular instant.
  • The operating system allocates memory for a program in RAM.
  • First instruction goes to the processor and resides in the instruction register.
  • This instruction is decoded by the control unit.
  • Control unit sends appropriate signals to ALU (Arithmetic Logic Unit) and ALU performs a specific task.
  • By the way registers, control unit and arithmetic logic unit are part of the processor. ALU is responsible for all kind of arithmetic, logical and shift instructions.
  • Similarly, next instruction moves to the processor and stored at the instruction register, control unit decode it and sends a signal to ALU.
  • Every instruction of the program executes same in a sequence. As soon as the last instruction is executed, the memory of the program will be released from RAM.

Execution Of C Program

C Program executes in four steps:

steps of execeution c program

  • Creating a Program: Create a Program that is also called as source code with an extension of “.c”.
  • Compiling a Program: Programs needs to be compiled in order to generate an object file which is containing the translated form of C program. In addition, a compiler translates source code into the operating system understandable format.
  • Linking a Program: Object file generated after compilation needs to be linked with library files needed for the execution of a program. This will give you an executable file (.exe).
  • Executing a Program: After successful linking of your compiled program, you will get the .exe file. This exe file will be your final software. Just double-click on that to enjoy your software.

Man Behind C Language

Dennis Ritchie is known as the founder of C Language. Dennis MacAlistair Ritchie was an American computer scientist. He created the C programming language with long-term associate Ken Thompson.

dennis ritchie

History Of C Language

  • It was developed at AT & T’s Bell Laboratories of the USA in 1972.
  • It is inspired by B language which was developed by Ken Thompson.
  • Approximately 80% of UNIX operating system is written in C Language.
  • C is middle-level language that is a combination of high level and low-level language.
  • It follows the procedure-oriented programming approach.
  • C follows a top-down approach.

IDE for C Programming

There are n numbers of IDE available for C language. They are specific to the operating system. I would recommend code::blocks, however, you can choose any IDE you want.Download code::blocks

IDE (Integrated Development Environment) is a software that provides facilities to write, edit, compile and run the code.

How to select perfect IDE to write C Program?

IDE normally consists of

  • A source code editor
  • Compiler or interpreter
  • Build automation
  • A debugger

Important Terms in C language

  • Syntax: Grammar for computer language
  • Compile: Process of compiling the source code and producing object code.
  • Debug: An activity to remove errors or bugs from source code.
  • Error : Mistakes in program like syntax error (compile time error),linker error,run time error,logical error.
  • Run: It means the execution of your program.

Have You enjoyed the article on Introduction to C Programming!

Let’s Understand Programming Structure

Let’s Write  First Program To Understand

Program in older IDEs like turbo
/* C Program To add two number */

#include <conio.h>
#include <stdio.h>
int main() //main function with return type integer
{
int a,b,c; //variable declaration
clrscr(); // clear console window
printf("Enter two numbers that you want to add");
scanf("%d %d", &a,&b); // input from user
c=a+b;
printf("Sum of %d and %d is %d",a,b,c); // printing result
getch(); // to hold screen to see output on console
return 0;
}

Understand Program Structure Step By Step

Since this is an article on Introduction to C Programming, so read each and everything slowly and carefully. Introduction to C Programming is necessary to build a foundation.

Header Files and Preprocessor Directives

  • The very first two lines are used to include statements written in specified files. Statements start from # symbol are known as preprocessor directives. Symbol # is followed by command include which tells to include the content of specified files.
  • The files stdio.h (standard input output) and conio.h (console input output)are one of the header files which contains the declaration of predefined function and declaration for other identifiers. Dot h(.h) is just extension written to denote it’s a header file. 
  • The stdio.h file contains declaration for printf() and scanf(). The conio.h file contains declaration for clrscr() and getch().
  • In the place of an angular bracket (<>) to include the header, you can write double quotes (“”). However, there is a big difference between these notations.
  • C language is a block-structured programming language. Pair of curly braces forms a block “{}”. Block contains instructions. In the above program, block name is identified by a name main().

Variables and Functions

  • Execution always begins with main() function. The prefix of main() is an integer, which says it returns some integer value.
  • The line int a,b,c declares variables which will be used to hold data.
  • clrscr() is used to clear the content of the output screen. But, you will use the system(“cls”) in code:: blocks or newer version of IDEs.
  • The next line is used to print a message on the screen to provide direction to the user. This is done with the help of a function printf().
  • The function scanf() is used to take input from the keyboard. Input data is then stored in the variables a and b which is declared previously.
  • Next line is an arithmetic instruction used to calculate the sum of values stored in a and b and result is then assigned to variable c.
  • Again function printf() is used to show the result on an output screen
  • getch() is used to get a character from the keyboard and this function call is required to hold the output screen. full form of getch() is get the character.
  • return 0 indicates main() function is of the return type integer.
  • Semicolon (;) indicates termination of a particular instruction.

NOTE

This is not optimised program, however good at beginner level. There are several ways you can write this program: taking void main() instead of int main(), not talking extra variable c and just print a+b instead of c and many more combination. Don’t worry you will learn each and every method that is essential for you on this website.

Why this program is not an optimized program?

Because this program includes unnecessary variable (C). Since variable consumes space of RAM and hence slows down the execution of the program.

Obviously, While writing a program, you must care about space and time complexity. In general term, you must focus on reducing the size of the program and the time of execution of the program.

But On code:: blocks or newer version of IDEs you won’t have to write clrscr(), instead you will write system(“cls”); and you need not to write getch(). Also, it’s not necessary to write two header files stdio.h and conio.h. However, it’s best practice to always include headers.

Have You enjoyed the article on Introduction to C Programming!

Summary Of Introduction to C Programming

  • The C Language is developed for creating system applications that directly interact with hardware devices such as drivers, kernels, etc.
  • Also, C programming is considered as the base for other programming languages. Therefore, it is known as mother language.
  • In addition, c is a middle-level language which follows the procedure-oriented approach. Therefore, it follows a top-down approach.

Buy our courses At Lowest Price

Hope You have enjoyed this article on ” Introduction to C Programming “. If yes then feel free to share this awesome article with your friends.

Your friends are waiting for this content. Please Share To Aware Them!

Authored By Rahul Kumar
An entrepreneur by the mind and a passionate blogger by heart ❤. I have started my carrier as a software developer and left an awesome job to become my own boss. I am a pro blogger, SEO expert and founder of many websites. However, currently giving my full time to mycteacher in order to create awesome content on c programming. Goal: Help People as much as possible.
https://MyCTeacher.com

Leave a Reply

Your email address will not be published. Required fields are marked *