coding – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Sun, 21 Aug 2022 07:06:41 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg coding – Programmerbay https://programmerbay.com 32 32 C Program to Draw Chess Board https://programmerbay.com/program-to-draw-a-chess-board-in-c/ https://programmerbay.com/program-to-draw-a-chess-board-in-c/#respond Fri, 12 Aug 2022 07:47:11 +0000 https://www.programmerbay.com/?p=2108 C supports a special header file named graphics.h that provides various functions through which one can draw different shapes such as line, circle, triangle, and more. And with the combination of these functions, we can create objects like a hut, joker, cap, and more.

The program draws a Chess board with the help of graphic libraries. It uses rectangle(), setcolor(), floodfill and setfillstyle() functions to draw this object.

C program to Draw Chess Board

 Program:

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main(){
int gr=DETECT,gm;
int row,col,x=50,y=50,flag=0;
initgraph(&gr,&gm,"C:\\TURBOC3\\BGI");
printf("\t*********** CHESS BOARD **************\n");
for(row=0;row<8;row++)
{

for(col=1;col<=8;col++){
if(flag==0){
setcolor(YELLOW);
setfillstyle(SOLID_FILL,BLACK);
rectangle(x,y,x+50,y+50);
floodfill(x+1,y+1,YELLOW);
flag=1;
}
else
{
setcolor(YELLOW);
setfillstyle(SOLID_FILL,WHITE);
rectangle(x,y,x+50,y+50);
floodfill(x+1,y+1,YELLOW);
flag=0;
}
x=x+50;
}
if(flag==0)
flag=1;
else
flag=0;
delay(100);
x=50;
y=50+y;
}
getch();
closegraph();
}

 

Output:

chessboard

]]>
https://programmerbay.com/program-to-draw-a-chess-board-in-c/feed/ 0
Difference between Compiler and Interpreter in Tabular Form https://programmerbay.com/difference-between-compiler-and-interpreter/ https://programmerbay.com/difference-between-compiler-and-interpreter/#respond Thu, 13 May 2021 17:05:50 +0000 https://programmerbay.com/?p=6271 A translator is used to translate a source code written in high level language to machine code, so, that computer can process and execute the converted code and provide the desired output. A compiler and interpreter are examples of such translators.

Compiler and interpreter are itself programs that are responsible for turning a source code to machine code.

Back in the days, people used to code in low level languages which could be directly processed in machine code. More or less, it was a set of instructions that was easy to process and understand by system.

A low level language is difficult to write, understand and debug. This is the reason, people start moving towards high level languages. Such as C++, Java and Python. As these languages were closer to natural language that a human can understand and easy to debug.

But the drawback was, these high level languages were not readable and understandable to computer system. Therefore, compilers and interpreter are used as code translators.

Difference between Interpreter and Compiler in Tabular form

CompilerInterpreter
It reads entire source code and translate it to machine codeIt reads, translates and executes each and every statement of a source code line by line
It produces intermediate code which can be executed afterwardsTranslation and execution of a source code take place together
It doesn't provide platform independent code. In other words, a executable produced on Window might not be run on Mac OSIt provides platform independent code
It generates an object code or executable
As it scans, translates and executes code on the fly, therefore, no intermediate code is generated
Java,Scala and C++ are some examplesJavaScript, Python and PHP are some examples
The object code can't be debuggedSince, the source code is visible. One can use and debug the source code
An object code runs faster and performs better as compared to InterpreterDue to line by line execution of a code, it serves slower code execution
Since, it is not platform independent. Therefore, it is not portableIt is portable
The source code doesn't need to be shared with others, instead an object code can be used directly on other systemsThe source code required to be shared, so that, interpreter can do its task

What is Compiler ?

compiler

A compiler reads entire source code first and translate it to machine code.

It produces an object code that can be executed later in single run.

However, it takes some time to scan, analyse and translate the provided code before producing executable.

Brief working of Compiler

compiler details

Lexer : it splits the code in tokens
Parser: It identifies grammar of the language and create a parse tree and then to syntax tree
Generator: converts the syntax tree to the desired language

What is Interpreter?

interperter

An interpreter reads a source code line by line and immediately executes it.

It doesn’t produce any executable, instead, it scans,translates and executes source code line-wise simultaneously.

In other words, it runs a code on fly. It does its work much faster, but it slows down the code execution speed and performance.

But behind the scenes, it scans a line from the source code, translate it and then execute it one by one until the interpreter scans last line of the code.

]]>
https://programmerbay.com/difference-between-compiler-and-interpreter/feed/ 0