Skip to main content

Introduction to C Program #DOTC_Mdb

Introduction to C Program.


Hello Everyone,

Today I will talk about basics of C language. In previous Blogs I almost completed SQL and PL/SQL parts will add more topics on DBA part. Previous Blogs you can see in my below blog where in archive you will able to see all the topics.

dheeraj60.blogspot.com

So Let’s Start with Basic Concept of C.

C is a most Popular Language in Computer Science as so many software’s built  by using C language like Microsoft Windows , Notepad , calculator , Games etc. C programming language is must for students and working professionals to become a good Software Engineer especially when they are working in Software Development Projects.  Key Advantage of C language is as below:

Structured Language

Very Easy to Learn

Produces Efficient Programs

C program can be compiled on variety of computer platforms

C Program can handle low-level activities

Note: In Today's world most popular  RDBMS Linux and OS have been written in C. C is also known as mother of all languages.

Before Starting To C Program we need to understand few important things:

As we Know Computer only understand Machine Language that is binary digit 0 and 1 in other word we can say computer can only understand Machine language (Stream of 0s and 1s).  So to convert our C program source code to Machine code, we need to compile it. So we use Compiler, which converts source code to Machine code. In other words we can say that a compiler converts human written code to a machine readable format. So we need compiler to write C program which used to convert human readable code to machine readable format.

For this we have several compilers available, so you need to install Turbo, code block etc.  Code Block you can easily install as it’s freeware and you can write starting code in C program.

 

Once you install any compiler you are able to write C program that will convert C program source code to Machine code.

 

So let’s start writing some simple program in C to display my name and understand how it works and what are the syntax, keywords used in that program.

Note : Later we need to know more about data type and other keywords which used in C program. Here  I am using code block as compiler  

First C Program to Display name:

Syntax is as below :

#include <stdio.h>

#include <stdlib.h>

int main()

{

    printf("Hello welcome to Diksha Oracle Training Centre !\n");

    return 0;

}

Once you compile the code and there is no Syntax error then output will be as below:

Hello welcome to Diksha Oracle Training Centre!

Let’s understand the Syntax for this program because if you want to write another code it’s useful for you to understand how it works after that I will show you the source code and output of this program in image. So please try to understand each syntax and keywords one by one.

 

#include <stdio.h>   --  stdio.h is the header file in C Program used for standard input and output. This is useful for getting the input from the user by using Keyboard and output result to the monitor/screen. Without header file, we can not able to display the results to the users on the screen or cannot input the values through the keyboard . Stdio.h is  contain the input and output operations like "printf" , "scanf" etc. print f used to display the output whereas scanf used to take input from the user .

 

#include <stdlib.h> --  stdlib stands for "standard library” whereas .h is header . stdlib.h is the header used for general purpose standard library of C programming language which includes functions involving memory allocation, process control, conversions and others.

int main() -- int main is a function that means that our function needs to return some integer so at the end of the execution and we do it by returning 0 at the end of the program. 0 is the standard for the successful execution of the program. In some compiler they used void main() so no need to worry as both are same. Return type for main function default is integer.

Printf – To print the value 

return 0 --  Since we use int main so we need to end the program by using return 0;

 

This is the basic Syntax  and it’s definition for this program as you should know about  this because when you write some other code it’s easy for you to write the program. Yes we need to know some other things as well when we write other code as per our requirement.

The output of above program image in code block is as below:



  

As we know about the basic Syntax and it’s uses we can write some other basic programs by using data types.

The Sum of two numbers Program in C  . Here in these program we only use data type int that is integer will explain the code after running the below code.

#include <stdio.h>

#include <stdlib.h>

int main()

{

    int a , b ,c ;

    a=10;

    b=20;

    c=a+b;

    printf("The Sum of 2 number is !\n %d",c);

    return 0;

}

 

Here in this program we use int as integer data type to take only numeric value . we take a , b and c as integer and assigned the value of a and b is 10 and 20 and in c we simply use addition to print the sum of two number that is a and b .

Note : in printf  we use %d for taking the value for output in integer in other word we can say %d is used to display integer type of value by using printf function and \n means it will go to new line . There is several keywords for anther data types that we will talk later when we write different programs.

 

The output of above program with source code and output in code block is as below :


 

 

 

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int a , b ,c ;

    printf("please enter two number \n");

    scanf("%d",&a);

    scanf("%d",&b);

        c=a+b;

    printf("The Sum of 2 number is !\n %d",c);

    return 0;

}

 

Here in this program  we simply use scanf to take input from user in integer that’s why we use %d in both scanf and & keyword for taking input from user. See the below source code and output of the above program in code block.


 Now we are able to write C program by simply taking output and also taking input from user . We can do the same program addition for 3 and 4 numbers in same manner . Please see the sum of four number code program below:

#include <stdio.h>

#include <stdlib.h>

 int main()

{

    int a , b ,c ,d ,e ;

    printf("please enter four number \n");

    scanf("%d",&a);

    scanf("%d",&b);

    scanf("%d",&c);

    scanf("%d",&d);

            e=a+b+c+d;

    printf("The Sum of 4 number is !\n %d",e);

    return 0;

}

 

Here we simply initialize 5 variables i.e a,b,c,d and e to get the sum of four numbers.

Output of the above Program with source code in Code block is as below :


 

 Hope you able to understand this Program . In same way we can use subtraction , multiplication , division program etc only thing we need to change the operator of value where we store like here we store in e =a+b+c+d ; so for multiplication we just need to change the operator from + to *. Please try to write some different programs with different operator for calculations.

Things to remember:

When we initialize any integer we need to close each value with semicolon that is ; same applied for input function scanf() and print f() . 

Today we only came to know about how to display output by using C program and by using data type integer we are able to write some piece of code for addition by taking user inputs or simply assigning hard value to get the result .

In next Blog I will come up with different data types like float(decimal values) , character etc and write some program accordingly and will cover some condition operations with examples and explain it accordingly.Please go through this blog Carefully as it will help you to write some basic codes in C Program and once you understand then it’s easy for you to jump on some other programs in C.

Please let me know if you have any doubts in today topic.

Thanks.

 

 

Comments

  1. Good for Students who want to learn computer science . C is very popular language and in this blog basics of C is well defined.

    ReplyDelete

Post a Comment

Popular posts from this blog

SQL and Classification of SQL in Oracle Database #Diksha Oracle Training Centre

  SQL and Classification of SQL in Oracle Database.   SQL is Structured Query Language , which is used for storing, manipulating and retrieving data stored in a relational database .SQL is the standard language for RDBMS. All the Relational Database Management Systems (RDMS) like Oracle, MySQL, Sybase, Informix, IBM DB2 and Microsoft SQL Server use SQL as their standard database language. Oracle is one of the more secured database as compared to other databases. Importance of   SQL : SQL and PL/SQL is a backend process where all data is stored and retrieved in GUI which created either by any programming languages like Java, C++, PHP etc. so we need to have very secure database so that there will be no impact for users. SQL allows users to access data in the relational database management systems. SQL is used to communicate with a database.SQL and PL/SQL allows users to create and drop databases tables , views , stored procedures , functions , packages , trigger etc. SQL allows

Materialized View uses and Benefits in Database #DOTC_Mdb

Materialized View uses and Benefits in Database. Hello Everyone, Today we will discuss about Materialized view as it’s play important role in database. We already discussed about Simple Views and complex views in my previous blog. Before Materialized view go through my previous blog which related to simple view. https://dheeraj60.blogspot.com/2020/05/benefits-of-creating-and-using-view-in.html As we know View is not a database object and not like table which is stored in database, but view can be created from base table a view is an SQL statement that’s stored in the database. This statement, or view, has a name.A view looks and acts a lot like a table. It has columns and rows, and can be included in SELECT queries just like a table. In other word we can say View is a virtual/logical table which is basically used for security purpose. Let’s understand   about   Materialized view : A materialized view is a view that stores the results of the view’s query. Whenever you query the ma

Top 50 Interview Questions On SQL and PL/SQL #DOTC_Mdb

                    Top 50 Interview Questions On SQL and PL/SQL. Today we will Discuss Top 50 interview questions and answers of SQL and PL/SQL which is frequently asked in interview.     Question 1: What is SQL and Classification of SQL? Answer SQL is a Structure Query Language which is vastly used in RDBMS database like Oracle, Sybase, DB2 , Microsoft SQL server etc.   Classification of SQL is as below: DDL (Data Definition Language):  Commands are  create , alter , drop , truncate etc DML (Data Manipulation Language) : Commands are  insert,update and delete . TCL (Transaction Control Language ) : Commands are  Commit , Rollback and Save point. DCL (Data Control Language) : Commands are Grant , Revoke Question 2:    What is meant by Joins? What are the types of join? Answer Joins are basically used to extract/get data from multiple tables using some common columns or conditions and also by using alias to fulfill the condition.   There are various types of Joins as li