Friday, February 1, 2019

Basics of Programming in C (part-1)


Hello Everyone!

After receiving a lot of support and encouragement from my parents, friends and well-wishers on behalf of my first blog, I am very excited to write more.
The main objective of this blog is to support engineering students especially first year students in understanding the concepts of C language.
As I am an engineering student I can closely relate to the problems that beginners will face while writing a code. This post will take approximately 5 minutes to complete it. I am sure that you are going to enjoy reading it. 
Welcome to the wonderful world of Programming 
Most of the people feels that it is very difficult (May be not you). But it is as simple as learning how to ride a bicycle.
We can’t ride a bicycle by simply learning it from some books like “RIDE A BICYCLE IN 30 DAYS!!”. First of all, we need a bicycle, a person who already know how to ride it (we should also trust that person 😊), courage and most importantly confidence on us that we can learn it.
Similarly, we can’t learn programming effectively if we are not practicing it. Don’t worry about making errors. I am sure that we all fell down at least once while learning to ride a bicycle. Making errors (or) mistakes are also the steps to learn something.
EACH MISTAKES TEACHES US SOMETHING
If we observe, the person who is guiding you while riding a bicycle is similar to a book while learning programming learning and the role of bicycle is similar to the role of some practice environment, in this case that role is played by compiler. If either one of them are not present then  I am sure that we can’t learn programming.
          I believe in interactive learning.
So, in order to make it interactive I strongly suggest you to practice and write programs.
PRACTICE MAKES PROGRAMMER BETTER
The reason why I didn't use the word "perfect" is we can’t bring perfection to our program. Always, there exists a better solution. That is the beauty of programming.
Tell me and I forget.
Teach me and I remember.
Involve me and I learn.
-          Benjamin Franklin

Where to practice? 
 I strongly recommend you guys to download any C compiler which are available for free of cost on internet. 
You can also practice on online compilers.
Some them are

You can go to the below link to download Dev C++ compiler. I prefer it because you can compile both C programs and C++ programs in it. 
You can also refer to the following video link from which you can learn how to use Dev C++ compiler. 
Wait. Hold on…... 
First of all, why do we need a compiler? 
We need a compiler to convert our programs which are written in high level languages (such as C, C++ etc) to low level language (machine code). Computer cannot understand the language we speak. It can only understand binary language which have only combinations of ‘0’ and ‘1’. 
Then why aren‘t  we  write programs in binary language? 
It is very difficult to write programs in binary language. Just imagine, whole code just containing 0 and 1. It will be terrific. 
In all my upcoming posts, I will try to explain the concepts through the programs. I will start with basics and try to cover all the necessary concepts which are important in a sequential manner. I am sure that you will get a kick start into the beautiful world of programming. 
Now the time has come……... 
Let us write our first C program!!!!! 
Our aim is  to display the text “I can do it” on the monitor. 
Open Dev C++, create a new source file (CTRL + N) and save it. 
Now type the below code in that source file. 
SOURCE CODE: 
#include<stdio.h>
int main()
{
            printf("I can do it.");
            return 0;
} 
 //END OF THE PROGRAM
Compile it by pressing fn+ F9 
Run it by pressing fn + F10 
output:  
output
Detailed explanation of above code:
Compiler starts compiling the program from the first line(top to bottom) and character by character(left to right). 
In the first line we used “#include<stdio.h>” which means that we are instructing compiler to include “stdio.h” file which is a header file. Std means  standard, I means input and O means  output.This file contains prototypes for some functions(we will see what are functions in upcoming posts) mainly for performing operations like taking input and displaying (or) printing output. Functions are basically represented as function_name(arguments). 
In the next line we wrote “int main()”. “int” is the returning type of the function “main”. Empty parenthesis indicates that function main takes no arguments. This is represents calling of main function which will return an integer.(Don’t worry if you are not able to understand this explanation , we are going to explain each and every important aspect of it in upcoming posts) 
Now we have a set of { } immediately after the main function, which indicates the all the statements that are included in between these parameters belongs to main function. 
Inside main function we wrote “printf(“I can do it”);” which is for displaying the text “I can do it”. 
The syntax of printf statement is
 printf(“…….. text……… ”) ; 
A semicolon ‘;’ is compulsory at the end of each statement. If we didn’t type semi-colon at the end of statement then compiler will give an error. 
After that we are returning the integer value zero.(we will discuss it later) 
We are closing the main function with ‘}’. 
         Now try yourself by replacing the text, without typing semi-colon etc. Explore it…...
After compiling and running the program, we can observe that printf statement displays whatever text is present in between the (“   _______    ”). 
In the next post I am going to cover very interesting and basic concepts of constants, variables, pointer and data-types. 
Share it with your co-geeks and help me to improve by giving feedback in the comments section below.
Thank you.
Thanks to Binshumesh Sachan for helping me in editing and Sumanth                Nidamanuri for helping me in adding more useful content.

Thanks alot to Nikhitha, Bhavani, Sadhana, Kailash varma, Devendhar, Manoj, Rakesh, Karthik, Koushik, Soma Sekhar and all other who are sharing these posts with their Co-geeks. Once again thank you guys. 

Next post:
https://codewithsujithsagar.blogspot.com/2019/02/basics-of-programming-in-c-part-2.html

ABOUT ME




MYSELF SUJITH SAGAR. I AM A B.tech SECOND YEAR  COMPUTER SCIENCE AND ENGINEERING STUDENT AT NATIONAL INSTITUTE OF TECHNOLOGY DELHI.

Linkedin profile: www.linkedin.com/in/sujith-sagar-gandi-2b3544179

           

5 comments:

  1. Can u distinguish the usage of void main () and int main()?

    ReplyDelete
    Replies
    1. The purpose of main's return value is to return an exit status to the operating system.Even if we don't return anything i.e return type is void, it is fine.

      Delete
  2. Congratulation for the great post. Those who come to read your Information will find lots of helpful and informative tips.
    get more: Programming in C

    ReplyDelete
  3. Excellent information you have shared, thanks for taking the time to share with us such a great article. I really appreciate your work. Also, click here for Learn Programming with C and C++ or many more.

    ReplyDelete

How Can You Test and Revert a Failover in Azure Cache for Redis Premium with Geo-Replication?

If you're using Azure Cache for Redis Premium with geo-replication across different regions, knowing how to test failover and revert it ...