Getting started with C | Program Compile Execute

Swapna Kategaru
Breach the code
Published in
3 min readDec 22, 2018

What is C ?

C is highly portable and robust language ,with rich set of built-in functions and can be useful to write any complex program.

Structure of a C- Program…

   /*Comment lines*/
DOCUMENTATION SECTION
#
include<header files>
LINK SECTION
#
defines symbolic constants
DEFINITION SECTION
declares data-type variables
GLOBAL DECLARATION SECTION
main() processes statements
MAIN FUNCTION SECTION
{
assigns value to variable
DECLARATION STATEMENT
prints the output function
EXECUTABLE STATEMENT
}
defines name to sub-programs
USER DEFINED FUNCTION SECTION
{
LOCAL DECLARATION
EXECUTABLE STATEMENTS
RETURN STATEMENT

}

Development of a program…

The development and execution of a program involves the following steps:

Image created from BeFunky

Creating a program…

Let’s start with a basic program called addition between two numbers.

Linking to C library for (stdio)standard input and output function.
here h refers to header.

#include<stdio.h>

Linking to c library for (conio)console input and output function.

#include<conio.h>

We use void function here since we are not returning and storing value of sum.
Every c program has this part function called main(), this part is enclosed with curly braces which includes all executable part of the program.

void main()
{

Initializing variables to integers.
Here a and b are our variables which we use to add two numbers and storing them in variable called ‘sum’.

int a, b, sum;

This function helps in clearing the screen from previous output of programs, let’s focus in current program output by clearing previous history.

clrscr();

‘printf’ stands for ‘print formatted’ function. It mainly refers to output library functions in C. They are complementary to scanf functions by copying their functions in output.
When compiler executes this line it will literally just prints what mentioned inside quote’s in output screen.
Syntax : printf(“control string”, list of parameters);

printf(“enter value for a\n”);

‘scanf’ stands for ‘scan formatted’ function. This function is used by compiler to read and write output in specific format.
Here %d refers to format descriptor for variable using int.
‘&a’ is a parameter, when compiler executes this line of code it searches it’s origin in above program or initialization.
Syntax : scanf(“control string”, list of parameters);

scanf(“%d”, &a);

This prints second variable value to the compiler.

printf(“enter value for b\n”);

This reads second value for variable ‘b’ .

scanf(“%d”, &b);

At this point compiler will add values of the two variables and stores in variable called ‘sum’.

sum = a + b;

First parameter will descript the value for integer variable and second parameter will return value stored in it.

printf(“sum of given values %d\n”, sum);

getch means get character from function, which refers to non-standard library <conio.h>.

getch();
}

Working with compiler…

A compiler is a system software, with special program that processes statements written in a programming language and turns it in a single step, into machine language or code that a computer’s processor uses.

The compiler is just a program and cannot fix your code for you. If you make a mistake, you need to correct the syntax or,else, it won’t compile.When we compile a program in C-compiler, it looks for errors and displays the message if anything is erratic, the page appears as follows :

After compiling the program, if there are no errors, you can finally run the program to get, an output result of your program.The output is displayed as shown below :

With the link provided below, you can install this (Turbo C++) compiler.

(Note : This compiler is not developed by me, it was officially developed in borland)

View full source code of above program in github.
GitHub

Thank you for reading !
This is my first story. If this helped, please make some noise doing claps.

--

--