Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

Introduction to C programming

What is C

 C is programming language developed at AT &T’s Bell Laboratory of USA in


1972.
 It was written by Dennis Ritchie.
 C is popular because it is reliable, simple and easy to use.
C Character Set

 A character denotes any alphabet, digit or special symbol used to represent


information. The following are valid alphabets, numbers and special
characters in C
 Alphabets : A…….Z,a….z
 Numbers : 0,1,….9
 Special Symbol :-~`!@#$%^&*()_-+=\|/”;:.,?/
Constant, Variables & Keywords

 Constant: is an entity that doesn’t change.


 Variable : is an entity that may change
 Keywords : are the reserved words.
 In the programming we do a lot of calculations. The result of these
calculations are stored in memory, the computer memory also contains no. of
cells. The calculated values are stored in the cells. To access these cells the
names are given to these cells. The name is called as variable name.
C Keywords

 Keywords are the words whose meaning is already explained to C compiler.


The keywords cannot used as variable name in c program
 These are also called as Reserved Word
 The are 32 keywords in C.
C Keywords
auto else long switch

break enum register typedef

case extern return union

char float short unsigned

const for signed void

continue goto sizeof volatile

default if static while

do int struct _Packed

double      
The First C Program
/* Calculation of Simple Interest*/
// This is Simple Program
#include<stdio.h> // Header File

void main() // main is function closed with paranthesis


{
int p,n; // Declare Variable Integer
float r,si;// Declare Real Variable
p=1000;
n=3;
r=8.5;
// Formula for Simple Interest
si=p*n*r/100;
printf("\n\t The Simple Interest %f",si);
}
Comment
 Comment is the part which is not executed. It is one type of
documentation.
 The Multi Line comments are put in /* put your comment */
 The single line comment is //
 Valid /* I am here */
 Comment cannot be nested ie. /* cal /*som*/*/
Reading Data/ Values
 The values of variables can be given at run time. For this purpose C provides the scanf()
function.
 The format of scanf is as follows
scanf(“% format string”,& variable name);

The format string is as follows:


For Integer %d, for Real %f, for Character %c & before variable name is an ‘ address of’
operator.
It will gives the location number used by the variable in memory.
Reading Data/ Values

 In the First Program the values of p,n,r are fixed. These can be changed by
scanf at runtime as follows:
printf(“ \nEnter the Value of Principal(P)\t”);
scanf(“%d”,&p);
printf(“ \nEnter the Value of n\t”);
scanf(“%d”,&n);
printf(“ \nEnter the Value Rate of Interest n\t”);
scanf(“%f”,&r);
Printing Values

 The format of printf statement is


 printf(“format string”,list of variables”);
 For printing Value of Sum of Interest(SI)
printf(“\nThe Sum of SI%f\t”,si);
\n New Line Print
\t Tab some spaces
printf(“\n the P is %d \t The n is%d\t the Rate is%f”,p,n,r);
C Instructions
 Declaration Instructions
 Arithmetic Instructions: Variable name of Left side of = and variable names &
constants on the right hand side of =.
e.g. int ad;
ad=3200;
Delta=alpha*beta/gamma+3.2*2/5
C Instructions
 C allows only one variable on left hand side of = ie. Z=k*j is allowed but k*j=z
is not allowed
 In addition to division operation it also allowed mod (%) operation which gives
remainder after division.
 i.e. 10/5=2 and 10%2=0. The modulus (%) operator cannot be applied to float
variable.
 The remainder sign is always equals to numerator sign i.e. -5%2= -1 and
5%-2=1
 Arithmetic operations can be performed on int, float and char.
 E.g
char x,y;
int z;
x=‘a’;
Y=‘b’;
z=x+y
It will print the ASCII value of a &b i.e. 97 and 98 and do the addition.

A=3**2 is not allowed


A=3^2 is not allowed.
To do this we have to use math.h file and function is a=pow(3,2);
Introduction to Compiler, Interpreter, Loader,
linker, debugger
• Compiler:
• A compiler is a computer program (or a set of programs) that transforms source code
written in a programming language (the source language) into another computer
language (the target language).
• Typically, from high level source code to low level machine code or object code.
 Example: C, C++, C#, Java
• Interpreter

• The translation of single statement of source program into machine code is done by
language processor and executes it immediately before moving on to the next line is
called an interpreter.

• An interpreter, like a compiler, translates high-level language into low-level machine


language. The difference lies in the way they read the source code or input. A
compiler reads the whole source code at once, creates tokens, checks semantics,
generates intermediate code, executes the whole program and may involve many
passes.
Compiler Interpreter

A compiler is a program which coverts the


interpreter takes a source program and
entire source code of a programming
runs it line by line, translating each line as
language into executable machine code for
it comes to it.
a CPU.
Compiler takes large amount of time to
Interpreter takes less amount of time to
analyze the entire source code but the
analyze the source code but the overall
overall execution time of the program is
execution time of the program is slower.
comparatively faster.

Compiler generates the error message only


after scanning the whole program, so Its Debugging is easier as it continues
debugging is comparatively hard as the translating the program until the error is
error can be present any where in the met
program.

Generates intermediate object code. No intermediate object code is generated.

Examples: C, C++, Java Examples: Python, Perl


• Linker
• Linker is a computer program that links and merges various object files together in order
to make an executable file. All these files might have been compiled by separate
assembler.
• The major task of a linker is to search and locate referenced module/routines in a
program and to determine the memory location where these codes will be loaded making
the program instruction to have absolute reference.

• Loader
• Loader is a part of operating system and is responsible for loading executable files into
memory and execute them.
• It calculates the size of a program (instructions and data) and create memory space for it.
It initializes various registers to initiate execution.
 What is a bug?

 A bug in software is a flaw, error, fault, or failure that causes the software to fail to
perform designated tasks.
 In simple words, when we make an error during coding, we call it a bug.
 We measure the impact of a bug on the software by means of two parameters,
namely – Severity and Priority.

 What is debugging?

 The process of finding and removing software errors which result in failure of the
software is known as debugging.
 The debugging phase starts just after receiving a bug report and ends when that bug
is removed and the program is working correctly.

You might also like