•Overview of C: History and importance C
•Algorithm :-”A set of finite rules or instructions to be followed in
calculations or other problem-solving operations.”
Therefore Algorithm refers to a sequence of finite steps to solve a
particular problem.
A set of steps that generates a finite sequence of elementary
computational operations leading to the solution of a given problem
is called an algorithm.
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
1
Example of algorithm for addition of two number
Step 1. INPUT TO A, B
Step 2. S ← A+B --(Store the sum of the values in A and B in S)
Step 3. PRINT S --(Show the sum obtained in Step 2)
Step 4. STOP
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
2
•Flowchart:-Aflowchartisablueprintthatpictoriallyrepresentsthealgorithmanditssteps.
•Formallyspeaking,aflowchartisadiagrammaticrepresentationofthestepsofanalgorithm.
•Inaflowchart,boxesofdifferentshapesareusedtodenotedifferenttypesofoperations.
Theseboxesarethenconnectedbylineswitharrowsdenotingtheflowordirectiontowhich
oneshouldproceedtoknowthenextstep.
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
3
Exampleofflowchart
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
4
C PROGRAM FOR ADDITION OF TWO NUMBER
# include<stdio.h>
#include<math.h>
Int main ()
{
int a , b , c ;
a = 5;
b = 7;
c = a + b;
printf(“%d”, c )
return 0;
}
10/8/2024
Fundamentals of Programming languages
5
•Overview of C: History and importance C
•Overview of C:
•Itis a general-purpose, procedure-oriented programming language.
•It is both machine-independent and structured. C is a high-level programming language
developed by Dennis Ritchie in the early 1970s.
•It is now one of the most popular and influential programming languages worldwide.
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
6
•History C
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
7
•Importance of C :
UNIT –I Introduction to Program Planning & C Programming
•C allows for direct memory manipulation and low-level
access to system resourcesEfficiency
•C code can be easily ported to different platforms & wide
availability of compilers and libraries.Portability
•C is known for its fast execution speed, making it suitable
for developing performance-critical applicationsSpeed
•C gives programmers fine-grained control over memory
management and system resourcesControl
•C code can be easily integrated with code written in other
languages like C++, Java, andPython
Compatibility
10/8/2024
Fundamentals of Programming languages
8
•Character Set :
charactersetreferstoasetofallthevalidcharactersthatwecanuseinthesourceprogram
forformingwords,expressions,andnumbers
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
9
Tokens in C :
ItisasmallestindividualelementoftheCprogramminglanguagethatismeaningfultothecompiler.
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
10
•Keywords :
ThesearewordsthathavespecialmeaningtotheCcompiler.
UNIT –I Introduction to Program Planning & C Programming
auto break case char const
continue default do double else
enum extern float for goto
if int long register return
short signed sizeof static struct
switch typedef union unsigned void
volatile while
10/8/2024
Fundamentals of Programming languages
11
•Identifiers:
Theseareuniquenamesthatareassignedtovariables,structs,
functions,andotherentities.
UNIT –I Introduction to Program Planning & C Programming
Sr.
No
Identifier Keyword
1 Anidentifierisauniquenamecreated
bytheprogrammertodefinea
variable,structure,class,orfunction.
Keywordsarerestrictedwordswithadefinite,
predeterminedmeaning.Anyprogramme
statementmaybedefinedwiththeaidof
keywords.
2
Akeywordalwaysstartsinlowercase.
Theinitialcharacterintheidentificationcan
becapitalized,lowercase,orstartwithan
underscore.
3
Itcanonlyhavealphabetical
characters.
Itcanhavenumbers,alphabeticalcharacters,
andunderscores.
4
Examplesofkeywordsaredouble,int,
auto,char,break,andmanyothers.
ExamplesofIDsaretest,count1,highspeed,
etc.
10/8/2024
Fundamentals of Programming languages
12
•Constants:
Itisavaluethatremainsconstantthroughouttheprogramand
cannotbechangedduringprogramexecution..
UNIT –I Introduction to Program Planning & C Programming
Constants
Primary
Integer
Real
Character
Secondary
Array
Pointer
Structure
Union
Enum , etc
10/8/2024
Fundamentals of Programming languages
13
•Variables :
Itisthenameassociatedwithsomememorylocationtostoredata
ofdifferenttypes.
CVariableSyntax
Datatypevariablename=value;
or
datatypevariable_name1,variable_name2;
Example
Intvar; // integer variable
char a; // character variable
float fff; // float variables
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
14
UNIT –I Introduction to Program Planning & C Programming
•Data types :
•It specifies the type of data that the variable can store like integer, character, floating,
double, etc.
10/8/2024
Fundamentals of Programming languages
15
UNIT –I Introduction to Program Planning & C Programming
•Declaration of variables:
•Themainpurposeofvariabledeclarationistostoretherequireddatainthememory
locationintheformofvariablessothatwecanusetheminourprogramtoperformany
operationortask.
•Example:
10/8/2024
Fundamentals of Programming languages
16
UNIT –I Introduction to Program Planning & C Programming
•StorageClassesinC
•CStorageClassesareusedtodescribethefeaturesofavariable/function.
•Thesefeaturesbasicallyincludethescope,visibility,andlifetimewhichhelpustotracetheexistence
ofaparticularvariableduringtheruntimeofaprogram.
10/8/2024
Fundamentals of Programming languages
17
UNIT –I Introduction to Program Planning & C Programming
•AssigningValuestovariables:
“Assigningavaluetoavariable”meanswritingavaluetothevariable.
Thisprocessinvolvesfourentities:
•A data type
•A variable
•The simple assignment operator (=)
•The value that will be copied to the variable.
10/8/2024
Fundamentals of Programming languages
18
UNIT –I Introduction to Program Planning & C Programming
•AssigningValuestovariables:
•Here:
•“ int ” is the data type.
•“ a ” is the variable.
•“ = " is the operator.
•“ 4 ” is the value.
“ int a = 4 ; ”
10/8/2024
Fundamentals of Programming languages
19
UNIT –I Introduction to Program Planning & C Programming
•DefiningSymbolicConstants:
•Labels/namesthatrepresentfixedvaluesthatneverchangeduringthecourseofa
program.
•Syntax for Creating Symbolic Constants
#definesymbolic_constant_name value_of_the_constant
•Symbolic Constants Examples
10/8/2024
Fundamentals of Programming languages
20
UNIT –I Introduction to Program Planning & C Programming
•declaringaVariableasConstant:
•TocreateaconstantinC,usetheconstkeywordfollowedbyadatatypeandavariable
name.
•example:
const int MAX_VALUE = 100;
ThiswillcreateaconstantvariablenamedMAX_VALUEwithavalueof100.
10/8/2024
Fundamentals of Programming languages
21
•Comparison between constants and variables :
UNIT –I Introduction to Program Planning & C Programming
Sr.
No
Constants Variables
1Aconstantdoesnotchangeits
valueastheequationissolved.
Avariable,ontheotherhand,changes
itsvaluedependingontheequation.
2Constantsareusuallywrittenin
numbers(whetherfractions,
integers,decimalsorreal
numbers).
Variablesarewrittenaslettersor
symbols.
3
Constantsusuallyrepresentthe
knownvaluesinanequationor
expression.
Variables,ontheotherhand,
representunknownvalues.
4
Constantshavefixedface
values.
Variablesdonothaveafixedface
value..
10/8/2024
Fundamentals of Programming languages
22
Declaring a Variable as Volatile:
•Whenavariableisdeclaredasvolatile,itindicatestothecompiler
thatthevariable’svaluemaychangeatanytimewithoutany
actionbeingtakenbythecodethecompilerfindsnearby.
•ThesyntaxforusingthevolatilekeywordinCisasfollows:
volatile data_type variable_name;
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
23
Example of Declaring a Variable as Volatile:
UNIT –I Introduction to Program Planning & C Programming
10/8/2024
Fundamentals of Programming languages
24