Tag Archives: Article

What is an interpreter and its need?

An interpreter is a program that translates source code written in high-level language to machine code. It is similar to compiler and does the same task of translation from high-level to low-level language. Despite of its similarity, the working mechanism of interpreter and compiler are different.

An interpreter does not translate whole code at once like compiler. Rather, is reads entire source code at once. Translates single instruction to machine code or some intermediate code. Then executes the translated machine code instruction immediately and translates next instruction if needed.

Continue reading What is an interpreter and its need?

Various programming paradigms

Programming paradigm is a way to classify programming languages according to their style of programming and features they provide. There are several features that determine a programming paradigm such as modularity, objects, interrupts or events, control flow etc. A programming language can be single paradigm or multi-paradigm.

With the wide spread of programming, various programming paradigms came into existence. Some popular programming paradigms are:

Imperative programming

Imperative programming is the oldest paradigm and is still in practice. It is the widely practiced paradigm in the day-to-day programming. It mainly focuses on steps to be done and works on the logic of “First do this then do that”. It defines a sequence of statements in order of which the operations must take place. In imperative programming, the control flow is explicit and depend on collection of GOTO statements. Imperative programming lacks the support of modularity.

Examples of imperative programming languages are – Assembly, C, C++, Java etc.

Continue reading Various programming paradigms

What is computer program and programming

Programming is an art, skill, poetry that is mastered through immense practice, patience, and experience. Before I formally define programming, let us talk about what is a computer program?

What is a computer program?

A Program is a set of instructions compiled together in a file to perform some specific task by the CPU (Central Processing Unit). It is a series of binary numbers (0s and 1s) arranged in a sequence, which when given to the computer performs some task.

Continue reading What is computer program and programming

How to create new C/C++ project in CodeBlocks

Hello friends, being a beginner to C/C++ everyone once had this question Where to write C/C++ codes? How to compile it? How to run it?. Codeblocks provides an ultimate solution to all these mentioned problems.

Code::Blocks is a IDE(Integrated Development Environment) for creating C/C++ projects. It is simple to use and provides very basic but powerful interface. CodeBlocks can be used for creating, editing, compiling, running and debugging C/C++ projects. Here is a beginner guide to use CodeBlocks.

Before preceding you must have Codeblocks with C/C++ compiler installed in your computer. If you don't have Codeblocks installed download and install it before moving to the next step.

Continue reading How to create new C/C++ project in CodeBlocks

What is ASCII character code?

ASCII stands for American Standard Code for Information Interchange. It was developed by ANSI (American National Standards Institute).

It is a set of decimal coded value for all basic printable and non-printable characters. For example - A is represented as 65 in ASCII standard. Similarly, there exists an integer value to represent every printable and non-printable character.

ASCII exists in two versions 7-bit ASCII and 8-bit ASCII. The first 7-bit version of ASCII contains 128 characters (including upper and lower case alphabets, digits, punctuations, special characters, non-printable and control characters). It uses 7 bit in memory to represent single character.
Later 7 bit variant of ASCII was extended to 8 bit and is popularly known as Extended ASCII. It uses 8 bit to represent a character and can represent upto 255 characters.

List of all ASCII character codes

Non-Printable ASCII characters
Printable ASCII characters
Extended ASCII characters

BinaryOctalDecimalHexadecimalSymbol
00000000000000NULL
00000001001101SOH
00000010002202STX
00000011003303ETX
00000100004404EOT
00000101005505ENQ
00000110006606ACK
00000111007707BEL
00001000010808BS
00001001011909HT
00001010012100ALF
00001011013110BVT
00001100014120CFF
00001101015130DCR
00001110016140ESO
00001111017150FSI
000100000201610DLE
000100010211711DC1
000100100221812DC2
000100110231913DC3
000101000242014DC4
000101010252115NAK
000101100262216SYN
000101110272317ETB
000110000302418CAN
000110010312519EM
00011010032261ASUB
00011011033271BESC
00011100034281CFS
00011101035291DGS
00011110036301ERS
00011111037311FUS
001000000403220SPACE
001000010413321!
001000100423422"
001000110433523#
001001000443624$
001001010453725%
001001100463826&
001001110473927'
001010000504028(
001010010514129)
00101010052422A*
00101011053432B+
00101100054442C,
00101101055452D-
00101110056462E.
00101111057472F/
0011000006048300
0011000106149311
0011001006250322
0011001106351333
0011010006452344
0011010106553355
0011011006654366
0011011106755377
0011100007056388
0011100107157399
00111010072583A:
00111011073593B;
00111100074603C<
00111101075613D=
00111110076623E>
00111111077633F?
010000001006440@
010000011016541A
010000101026642B
010000111036743C
010001001046844D
010001011056945E
010001101067046F
010001111077147G
010010001107248H
010010011117349I
01001010112744AJ
01001011113754BK
01001100114764CL
01001101115774DM
01001110116784EN
01001111117794FO
010100001208050P
010100011218151Q
010100101228252R
010100111238353S
010101001248454T
010101011258555U
010101101268656V
010101111278757W
010110001308858X
010110011318959Y
01011010132905AZ
01011011133915B[
01011100134925C
01011101135935D]
01011110136945E^
01011111137955F_
011000001409660`
011000011419761a
011000101429862b
011000111439963c
0110010014410064d
0110010114510165e
0110011014610266f
0110011114710367g
0110100015010468h
0110100115110569i
011010101521066Aj
011010111531076Bk
011011001541086Cl
011011011551096Dm
011011101561106En
011011111571116Fo
0111000016011270p
0111000116111371q
0111001016211472r
0111001116311573s
0111010016411674t
0111010116511775u
0111011016611876v
0111011116711977w
0111100017012078x
0111100117112179y
011110101721227Az
011110111731237B{
011111001741247C|
011111011751257D}
011111101761267E~
011111111771277FDEL
1000000020012880Ç
1000000120112981ü
1000001020213082é
1000001120313183â
1000010020413284ä
1000010120513385à
1000011020613486å
1000011120713587ç
1000100021013688ê
1000100121113789ë
100010102121388Aè
100010112131398Bï
100011002141408Cî
100011012151418Dì
100011102161428EÄ
100011112171438FÅ
1001000022014490É
1001000122114591æ
1001001022214692Æ
1001001122314793ô
1001010022414894ö
1001010122514995ò
1001011022615096û
1001011122715197ù
1001100023015298ÿ
1001100123115399Ö
100110102321549AÜ
100110112331559B¢
100111002341569C£
100111012351579D¥
100111102361589E
100111112371599Fƒ
10100000240160A0á
10100001241161A1í
10100010242162A2ó
10100011243163A3ú
10100100244164A4ñ
10100101245165A5Ñ
10100110246166A6ª
10100111247167A7º
10101000250168A8¿
10101001251169A9
10101010252170AA¬
10101011253171AB½
10101100254172AC¼
10101101255173AD¡
10101110256174AE«
10101111257175AF»
10110000260176B0
10110001261177B1
10110010262178B2
10110011263179B3
10110100264180B4
10110101265181B5
10110110266182B6
10110111267183B7
10111000270184B8
10111001271185B9
10111010272186BA
10111011273187BB
10111100274188BC
10111101275189BD
10111110276190BE
10111111277191BF
11000000300192C0
11000001301193C1
11000010302194C2
11000011303195C3
11000100304196C4
11000101305197C5
11000110306198C6
11000111307199C7
11001000310200C8
11001001311201C9
11001010312202CA
11001011313203CB
11001100314204CC
11001101315205CD
11001110316206CE
11001111317207CF
11010000320208D0
11010001321209D1
11010010322210D2
11010011323211D3
11010100324212D4
11010101325213D5
11010110326214D6
11010111327215D7
11011000330216D8
11011001331217D9
11011010332218DA
11011011333219DB
11011100334220DC
11011101335221DD
11011110336222DE
11011111337223DF
11100000340224E0α
11100001341225E1ß
11100010342226E2Γ
11100011343227E3π
11100100344228E4Σ
11100101345229E5σ
11100110346230E6µ
11100111347231E7τ
11101000350232E8Φ
11101001351233E9Θ
11101010352234EAΩ
11101011353235EBδ
11101100354236EC
11101101355237EDφ
11101110356238EEε
11101111357239EF
11110000360240F0
11110001361241F1±
11110010362242F2
11110011363243F3
11110100364244F4
11110101365245F5
11110110366246F6÷
11110111367247F7
11111000370248F8°
11111001371249F9
11111010372250FA·
11111011373251FB
11111100374252FC
11111101375253FD²
11111110376254FE
11111111377255FF

What are Escape sequence characters?

Escape characters are sequence of characters that are converted to some another character which are difficult or impossible to print directly. Characters such as new lines, you cannot print a new line directly in any programming language by hitting enter key. To print new line an special character is given \n which is later converted to new line by compiler. Likewise there are many escape sequence character used in programming languages.

An escape character begin with backward slash \ followed by escape character.

List of all escape sequence characters

Escape characterDescription
\0NULL
\aAlert (Beep)
\bBackspace
\eEscape
\fFormfeed (Return)
\nNew line
\rCarriage return
\tHorizontal Tab (Eight blank spaces)
\vVertical Tab
\\Backslash
\'Single quotes
\"Double quotes
\?Question mark

How to find the size of data type using sizeof() operator in C

Sizeof(type) is a unary operator used to calculate the size(in bytes) of any datatype in C.

Syntax:

sizeof(type)
Note: type must be replaced by a valid C data type or variable.

Example:


#include <stdio.h>

int main()
{
int i;
printf("Size of int = %dn", sizeof(int));
printf("Size of i = %dn", sizeof(i));
return 0;
}

Output:

Size of int = 4
Size of i = 4

Calculating the size of struct and array:


#include <stdio.h>

struct Student {
int roll; //Will take 4 bytes
char name[30] //Will take total 1*30 bytes
}stu;

int main()
{
printf("Size of Student = %dn", sizeof(struct Student));
printf("Size of Student = %dn", sizeof(stu));
printf("Size of Student.roll = %dn",sizeof(stu.roll));
printf("Size of Student.name = %dn",sizeof(stu.name));

return 0;
}

Output:

Size of Student = 36
Size of Student = 36
Size of Student.roll = 4
Size of Student.name = 30

Note: size of struct should be 34 bytes buts its takes 36 bytes because the compiler adds extra 1 byte for alignment and performance at the end of each structure members.

Program to calculate size of different data types:


#include <stdio.h>

int main()
{
printf("Size of char = %dn", sizeof(char));
printf("Size of short = %dn", sizeof(short));
printf("Size of int = %dn", sizeof(int));
printf("Size of long = %dn", sizeof(long));
printf("Size of long long = %dn", sizeof(long long));
printf("Size of float = %dn", sizeof(float));
printf("Size of double = %dn", sizeof(double));
printf("Size of long double = %dn", sizeof(long double));

return 0;
}

Output:

Size of char = 1
Size of short = 2
Size of int = 4
Size of long = 4
Size of long long = 8
Size of float = 4
Size of double = 8
Size of long double = 12

Note: All size are in bytes and may vary on different platform.

Introduction to Programming – Errors

Errors are the mistakes or faults in the program that causes our program to behave unexpectedly and it is no doubt that the well versed and experienced programmers also makes mistakes. Programming error are generally known as Bugs and the process to remove bugs from program is called as Debug/Debugging.

There are basically three types of error:

  1. Compilation error or Syntax error
  2. Runtime error or exception
  3. Logical error

Compilation error

Compilation errors are the most common error occurred due to typing mistakes or if you don't follow the proper syntax of the specific programming language. These error are thrown by the compilers and will prevent your program from running. These errors are most common to beginners. It is also called as Compile time error or Syntax error. These errors are easy to debug.

Example: Typing int as Int

Runtime error

Run Time errors are generated when the program is running and leads to the abnormal behavior or termination of the program. The general cause of Run time errors is because your program is trying to perform an operation that is impossible to carry out.

Example: Dividing any number by zero, Accessing any file that doesn't exist etc are common examples of such error.

Logical error

Logical error will cause your program to perform undesired operations which you didn't intended your program to perform. These errors occur generally due to improper logic used in program. These types of errors are difficult to debug.

Example: Multiplying an uninitialized integer value with some other value will result in undesired output.