Skip to main content

COMPLETE 'C' PROGRAMMING FOR BEGINNERS.

 COMPLETE 'C' PROGRAMMING FOR BEGINNERS.

            If you have taken  CS or IT course and you don't know anything about programming or simply you have interest in programming then this blog is meant specially for you'll. In this blog I'll be discussing about the syntax, compilation, execution, datatypes, variables, which software to use... etc for C programming. So lets begin.





INTRODUCTION:

           As we all know C language is a high-level programming language which uses compiler to compile codes into binary language(computer language comprising of 1's and 0's) and  then into human readable language i.e. english language. It is  considered as the mother of all programming languages and was developed by Dennis Ritchie(computer scientist) in 1972 at Bell laboratories. If you learn C language completely, it'll be easy for you to learn other programming languages such as C++,C#,JAVA, PYTHON etc.

SYNTAX:

           You'll be wondering, what is Syntax? Let me tell you it's nothing but a format or simply a method used to write any programming language, like we have steps to solve a question in mathematics. And every programming language has it's own syntax.

SYNTAX FOR C LANGUAGE;

#include<stdio.h>                        #include<conio.h>                                                    main( )                                                                      {                                                                                                                                                    _________________________                                                                                                  _________________________                                                                                                  _________________________                           }

           On the first line I have written #include<stdio.h> and on second line #include<conio.h> these  are commands that informs the compiler to perform preprocessing before doing actual compilation of the program. #include is a preprocessor directive  which tells a C compiler to include stdio.h which is a header file before going to actual compilation which contains function support for input output operations. When compiler encounters printf( ) function and doesn't finds stdio.h header file, it shows error. printf  is used to display content on the screen which is within the quotation. Here main( ) is a part of the function from where the execution starts, which may access other functions. { is open curly brace from where we start writing the code or a program and } is close curly brace where the program ends. Within these curly braces the program is executed. 



DATATYPES AND VARIABLES:

         It is very important for you'll to learn datatypes and variables to write a program. These are very important concepts in C language because without knowing what are datatypes and variables you will not be able to write a program in C language. So, basically there 2 types of datatypes- 1: Primary Data Types and,

                                            2: Secondary Data Types.

In primary datatypes we have char, int, float ,double etc. While in secondary datatypes we have arrays, pointers, structures etc. Since, we do not have any programming language, we'll be learning only primary datatypes this blog. Once you master to write programs using primary datatypes you can further go for secondary datatypes. 

        If you want to store any values in the memory of the computer you cannot store it without any specification. You have to declare the data type of that value, declare the variable name so that you can allocate a memory to that value in your computer or laptop let it be a number or a name.                                                                                                                  As we are learning primary datatypes, we must know what are they used for.                   Here, int is used to store any integer value or simply to store numbers,                                            char is used to store character value,                                                                                          float is used to store point value or simply decimal value,                                                        double is same as float and used to store decimal value but it requires more storage than float. 



         Now, if we have to declare a variable or a datatype, we need to use the syntax used for declaring any variable or datatype like we have a syntax to write program in C language. 

Here, first we must write the data type then we must write the variable name and then use semi colon ; symbol. It is very important to use semi-colon symbol at the end of every line because it indicates the termination of a line.

For Example: If we want to store an integer value we will use int data type. Then we need to declare a variable for it, suppose we take x as the variable name. Then, we write it as,

int  x; 

as soon as we declare the data type and variable name there is a memory allocated in the memory of the computer for that value. 

Now we know what is syntax of C language, what are datatypes and variables and how to declare them. Now the last but most important thing that you will need to write any program in C are keywords. So you must know what are keywords? Keywords are pre-defined functions that we must use to write programs in C language. 

Here, printf is the most important keyword that is used to display or print output on the computer screen. 

scanf  is another important keyword used to assign any value or input data from the user. 

Now we have to use datatypes. For int datatype we use %d to show integer value, %f for float value and  %c for character value. Here, %d, %f, and %c are format specifiers used to represent their data types. Remember while displaying the result you must write these format specifier for their respective data types. 

 Now, lets write a simple program:



Example 1- write a program to display message HELLO WORLD. 


 #include<stdio.h>                     #include<conio.h>                                     main( )                                                                         {                                                                                     printf("\n HELLO WORLD");                       getch( );                                                                                                      }

 
OUTPUT: HELLO WORLD

Explanation :
#include is a command that is used to include the header file- stdio.h. conio.h is a header file that gives access to use the getch function which holds the output screen.  " " are the quotations in which we write a statement that must be printed on the output screen. \n is used to write the statement on a new line.  So here your first C program is ready. 

Thank you for your patience!



























Comments