SlideShare a Scribd company logo
1 of 45
Download to read offline
Fundamentals of C Programming Language
and
Dept. of CS&E nad IT, DBCET, Guwahati1
Basic Input / Output Functions
Fundamentals of C and Input/Output
Content:
History of C
Why C?
C Development Environment
C Program Structure
Basic Data Types
Dept. of CS&E nad IT, DBCET, Guwahati2
Basic Data Types
Input/Output function
Common Programming Error
History of C
In 1972 Dennis Ritchie at Bell Labs writes C and in
1978 the publication of The C Programming
Language by Kernighan & Ritchie caused a revolution in
the computing world
In 1983, the American National Standards Institute (ANSI)
Dept. of CS&E nad IT, DBCET, Guwahati3
In 1983, the American National Standards Institute (ANSI)
established a committee to provide a modern,
comprehensive definition of C.The resulting definition,
the ANSI standard, or "ANSI C", was completed late
1988.
History of C [contd..]
Evolved from two previous languages
BCPL , B
BCPL (Basic Combined Programming Language) used for
writing OS & compilers
B used for creating early versions of UNIX OS
Dept. of CS&E nad IT, DBCET, Guwahati4
B used for creating early versions of UNIX OS
Why C Still Useful?
C provides:
Efficiency, high performance and high quality s/ws
flexibility and power
many high-level and low-level operations middle level
Stability and small size code
Provide functionality through rich set of function libraries
Gateway for other professional languages like C C++ Java
Dept. of CS&E nad IT, DBCET, Guwahati5
Gateway for other professional languages like C C++ Java
C is used:
System software Compilers, Editors, embedded systems
data compression, graphics and computational geometry, utility
programs
databases, operating systems, device drivers, system level routines
Also used in application programs
C Development Environment
DiskPhase 2 :
Preprocessor
program
processes the
code.
Preprocessor
EditorPhase 1 :
Program is
created using the
Editor and
stored on Disk.
Disk
Dept. of CS&E nad IT, DBCET, Guwahati6
code.
DiskCompilerPhase 3 :
Compiler
creates object
code and stores
it on Disk.
DiskLinkerPhase 4 :
Linker links object
code with libraries,
creates a.out and
stores it on Disk
C Development Environment cont
LoaderPhase 5 :
:
.
Primary
Memory
Loader puts
Program in
Memory
Dept. of CS&E nad IT, DBCET, Guwahati7
.
C P U (execute)Phase 6 :
:
.
Primary
Memory
CPU takes each
instruction and
executes it, storing
new data values as
the program executes.
Dept. of CS&E nad IT, DBCET, Guwahati8
Entering, translating, and running a High-Level Language
Program
C Program Structure
An example of simple program in C
#include <stdio.h>
void main(void)
{
Dept. of CS&E nad IT, DBCET, Guwahati9
{
printf(“Welcome to Programmingn”);
printf(“This is my first program in C language”);
}
The output
The previous program will produce the following output
on your screen
Welcome to Programming
This is my first program in C language
Dept. of CS&E nad IT, DBCET, Guwahati10
This is my first program in C language
Preprocessor directives
A C program line begins with # provides an instruction to
the C preprocessor (built into a C Compiler)
It is executed before the actual compilation is done.
It causes the preprocessor to include a copy of the
header file at that point of code.
Dept. of CS&E nad IT, DBCET, Guwahati11
In our example (#include<stdio.h>) identifies the header
file for standard input and output needed by the printf().
Angle brackets indicate that the file is to be found in the
usual place, which is system dependent.
Function main
Identify the start of the program
Every C program has a main ( )
'main' is a C keyword. We must not use it for any
other variable.
4 common ways of main declaration
Dept. of CS&E nad IT, DBCET, Guwahati12
4 common ways of main declaration
int main(void)
{
return 0;
}
void main(void)
{
}
main(void)
{
}
main( )
{
}
The curly braces { }
Identify a segment / body of a program
The start and end of a function
The start and end of the selection or repetition block.
Since the opening brace indicates the start of a segment
with the closing brace indicating the end of a segment,
there must be just as many opening braces as
Dept. of CS&E nad IT, DBCET, Guwahati13
with the closing brace indicating the end of a segment,
there must be just as many opening braces as
closing braces (this is a common mistake of beginners)
Statement
A specification of an action to be taken by the computer as
the program executes.
Each statement in C needs to be terminated with semicolon
(;)
Example:
#include <stdio.h>
Dept. of CS&E nad IT, DBCET, Guwahati14
#include <stdio.h>
void main(void)
{
printf(“I love programmingn”);
printf(“You will love it too once ”);
printf(“you know the trickn”);
}
statement
statement
statement
Statement cont…
Statement has two parts :
Declaration
The part of the program that tells the compiler the names of memory
cells in a program
Executable statements
Program lines that are converted to machine language instructions
and executed by the computer
Dept. of CS&E nad IT, DBCET, Guwahati15
and executed by the computer
C program skeleton
In short, the basic skeleton of a C program looks like this:
#include <stdio.h>
void main(void)
{
Preprocessor directives
Function main
Start of segment
Dept. of CS&E nad IT, DBCET, Guwahati16
statement(s);
} End of segment
Identifiers
Words used to represent certain program entities
(variables, function names, etc).
Example:
int my_name;
my_name is an identifier used as a program variable
void CalculateTotal(int value)
Dept. of CS&E nad IT, DBCET, Guwahati17
void CalculateTotal(int value)
CalculateTotal is an identifier used as a function name
Rules for naming identifiers
Rules Example
Can contain a mix of characters and numbers.
However it cannot start with a number
H2o
First character must be a letter or underscore Number1;
_area
Can be of mixed cases including underscore XsquAre
Dept. of CS&E nad IT, DBCET, Guwahati18
Can be of mixed cases including underscore
character
XsquAre
my_num
Cannot contain any arithmetic operators R*S+T
or any other punctuation marks #@x%!!
Cannot be a C keyword/reserved word struct; printf;
Cannot contain a space My height
identifiers are case sensitive Tax != tax
Variables
Variable a name associated with a memory cell
whose value can change
Variable Declaration: specifies the type of a variable
Example: int num;
Dept. of CS&E nad IT, DBCET, Guwahati19
Variable Definition: assigning a value to the declared
variable
Example: num = 5;
Basic Data Types
There are 4 basic data types :
int
float
double
char
int
Dept. of CS&E nad IT, DBCET, Guwahati20
int
used to declare numeric program variables of integer type
whole numbers, positive and negative
keyword: int
int number;
number = 12;
Basic Data Types cont…
float
fractional parts, positive and negative
keyword: float
float height;
height = 1.72;
double
Dept. of CS&E nad IT, DBCET, Guwahati21
double
used to declare floating point variable of higher precision
or higher range of numbers
exponential numbers, positive and negative
keyword: double
double valuebig;
valuebig = 12E-3;
Basic Data Types cont…
char
equivalent to ‘letters’ in English language
Example of characters:
Numeric digits: 0 - 9
Lowercase/uppercase letters: a - z and A - Z
Space (blank)
Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc
Dept. of CS&E nad IT, DBCET, Guwahati22
Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc
single character
keyword: char
char my_letter;
my_letter = 'U';
The declared character must be
enclosed within a single quote!
Constants
Entities that appear in the program code as fixed values.
Any attempt to modify a CONSTANT will result in error.
4 types of constants:
Integer constants
Positive or negative whole numbers with no fractional part
Example:
const int MAX_NUM = 10;
Dept. of CS&E nad IT, DBCET, Guwahati23
const int MAX_NUM = 10;
const int MIN_NUM = -90;
Floating-point constants (float or double)
Positive or negative decimal numbers with an integer part, a decimal
point and a fractional part
Example:
const doubleVAL = 0.5877e2; (stands for 0.5877 x
102)
Constants cont…
Character constants
A character enclosed in a single quotation mark
Example:
const char letter = ‘n’;
const char number = ‘1’;
printf(“%c”,‘S’);
Output would be: S
Dept. of CS&E nad IT, DBCET, Guwahati24
Output would be: S
Enumeration
Values are given as a list
Example:
enum Language {
Malay,
English,
Arabic
};
Constant example – volume of a cone
#include <stdio.h>
void main(void)
{
const double pi = 3.142;
double height, radius, base, volume;
printf(“Enter the height and radius of the cone:”);
Dept. of CS&E nad IT, DBCET, Guwahati25
printf(“Enter the height and radius of the cone:”);
scanf(“%lf %lf”,&height, &radius);
base = pi * radius * radius;
volume = (1.0/3.0) * base * height;
printf(“nThe volume of a cone is %lf ”, volume);
}
#define
You may also associate constant using #define preprocessor directive
#include <stdio.h>
#define pi 3.142
void main(void)
{
double height, radius, base, volume;
Dept. of CS&E nad IT, DBCET, Guwahati26
printf(“Enter the height and radius of the cone:”);
scanf(“%lf %lf”,&height,&radius);
base = pi * radius * radius;
volume = (1.0/3.0) * base * height;
printf(“nThe volume of a cone is %lf ”, volume);
}
Input/Output Operations
Input operation
an instruction that copies data from an input device into
memory
Output operation
an instruction that displays information stored in memory to
Dept. of CS&E nad IT, DBCET, Guwahati27
an instruction that displays information stored in memory to
the output devices (such as the monitor screen)
Input/Output Functions
A C function that performs an input or output operation
A few functions that are pre-defined in the header file
stdio.h such as :
printf()
scanf()
Dept. of CS&E nad IT, DBCET, Guwahati28
getchar() & putchar()
The printf function
Used to send data to the standard output (usually
the monitor) to be printed according to specific
format.
General format:
printf(“string literal”);
Dept. of CS&E nad IT, DBCET, Guwahati29
printf(“string literal”);
A sequence of any number of characters surrounded by double
quotation marks.
printf(“format string”, variables);
Format string is a combination of text, conversion specifier and
escape sequence.
The printf function cont…
Example:
printf(“Thank you”);
printf (“Total sum is: %dn”, sum);
%d is a placeholder (conversion specifier)
marks the display position for a type integer variable
n is an escape sequence
Dept. of CS&E nad IT, DBCET, Guwahati30
n is an escape sequence
moves the cursor to the new line
Escape Sequence
Escape Sequence Effect
a Beep sound
b Backspace
f Formfeed (for printing)
n New line
r Carriage return
Dept. of CS&E nad IT, DBCET, Guwahati31
r Carriage return
t Tab
v Vertical tab
 Backslash
” “ sign
o Octal decimal
x Hexa decimal
0 NULL
Placeholder / Conversion Specifier
No Conversion
Specifier
Output Type Output Example
1 %d Signed decimal integer 76
2 %i Signed decimal integer 76
3 %o Unsigned octal integer 134
4 %u Unsigned decimal integer 76
5 %x Unsigned hexadecimal (small letter) 9c
6 %X Unsigned hexadecimal (capital letter) 9C
Dept. of CS&E nad IT, DBCET, Guwahati32
6 %X Unsigned hexadecimal (capital letter) 9C
7 %f Integer including decimal point 76.0000
8 %e Signed floating point (using e notation) 7.6000e+01
9 %E Signed floating point (using E notation) 7.6000E+01
10 %g The shorter between %f and %e 76
11 %G The shorter between %f and %E 76
12 %c Character ‘7’
13 %s String “76”
The scanf function
Read data from the standard input device (usually
keyboard) and store it in a variable.
General format:
scanf(“Format string”, &variable);
Notice ampersand (&) operator :
Dept. of CS&E nad IT, DBCET, Guwahati33
Notice ampersand (&) operator :
C address of operator
it passes the address of the variable instead of the variable
itself
tells the scanf() where to find the variable to store the new
value
The scanf function cont…
Example :
int age;
printf(“Enter your age:“);
scanf(“%d”, &age);
Common Conversion Identifier used in printf and
Dept. of CS&E nad IT, DBCET, Guwahati34
Common Conversion Identifier used in printf and
scanf functions.
printf scanf
int %d %d
float %f %f
double %f %lf
char %c %c
string %s %s
The scanf function cont…
If you want the user to enter more than one value, you
serialise the inputs.
Example:
float height, weight;
Dept. of CS&E nad IT, DBCET, Guwahati35
printf(“Please enter your height and weight:”);
scanf(“%f%f”, &height, &weight);
getchar() and putchar()
getchar() - read a character from standard input
putchar() - write a character to standard output
Example:
#include <stdio.h>
void main(void)
Dept. of CS&E nad IT, DBCET, Guwahati36
void main(void)
{
char my_char;
printf(“Please type a character: ”);
my_char = getchar();
printf(“nYou have typed this character: ”);
putchar(my_char);
}
getchar() and putchar() cont
Alternatively, you can write the previous code using
normal scanf and %c placeholder.
Example
#include <stdio.h>
void main(void)
Dept. of CS&E nad IT, DBCET, Guwahati37
void main(void)
{
char my_char;
printf(“Please type a character: ”);
scanf(“%c”,&my_char);
printf(“nYou have typed this character: %c ”, my_char);
}
Few notes on C program…
C is case-sensitive
Word, word,WorD,WORD,WOrD, worD, etc are all different
variables / expressions
Eg. sum = 23 + 7
What is the value of Sum after this addition ?
Dept. of CS&E nad IT, DBCET, Guwahati38
Comments (remember 'Documentation')
are inserted into the code using /* to start and */ to end a
comment
Some compiler support comments starting with ‘//’
Provides supplementary information but is ignored by the
preprocessor and compiler
/* This is a comment */
// This program was written by me
Few notes on C program cont…
ReservedWords
Keywords that identify language entities such as statements,
data types, language attributes, etc.
Have special meaning to the compiler, cannot be used as
identifiers (variable, function name) in our program.
Should be typed in lowercase.
Dept. of CS&E nad IT, DBCET, Guwahati39
Should be typed in lowercase.
Example: const, double, int, main, void,printf, while, for, else
(etc..)
Few notes on C program cont…
Punctuators (separators)
Symbols used to separate different parts of the C program.
These punctuators include:
[ ] ( ) { } , ;“: * #
Usage example:
Dept. of CS&E nad IT, DBCET, Guwahati40
void main (void)
{
int num = 10;
printf (“%d”, num);
}
Few notes on C program cont…
Operators
Tokens that result in some kind of computation or action when
applied to variables or other elements in an expression.
Example of operators:
* + = - /
Dept. of CS&E nad IT, DBCET, Guwahati41
Usage example:
result = total1 + total2;
Common Programming Errors
Debugging Process removing errors from a
program
Three (3) kinds of errors :
Syntax Error
Dept. of CS&E nad IT, DBCET, Guwahati42
Syntax Error
a violation of the C grammar rules, detected during
program translation (compilation).
statement cannot be translated and program cannot
be executed
Common Programming Errors cont…
Run-time errors
An attempt to perform an invalid operation, detected
during program execution.
Occurs when the program directs the computer to
perform an illegal operation, such as dividing a
number by zero.
Dept. of CS&E nad IT, DBCET, Guwahati43
number by zero.
The computer will stop executing the program, and
displays a diagnostic message indicates the line where
the error was detected
Common Programming Errors cont…
Logic Error/Design Error
An error caused by following an incorrect algorithm
Very difficult to detect - it does not cause run-time error and does
not display message errors.
The only sign of logic error – incorrect program output
Can be detected by testing the program thoroughly,comparing its
output to calculated results
To prevent – carefully desk checking the algorithm and written
Dept. of CS&E nad IT, DBCET, Guwahati44
To prevent – carefully desk checking the algorithm and written
program before you actually type it
Summary
You have learned the following items:
History of C and related topics
Environment of C language and C programming
C language elements
Preprocessor directives, curly braces, main (), semicolon, comments,
double quotes
Dept. of CS&E nad IT, DBCET, Guwahati45
double quotes
4 basics data type and brief explanation on variable
6 tokens : reserved word, identifier, constant, string literal,
punctuators / separators and operators.
printf, scanf, getchar and putchar
Usage of modifiers : placeholder & escape sequence
Common programming errors : syntax error, run-time error and
logic error

More Related Content

What's hot

C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageVincenzo De Florio
 
Chapter3
Chapter3Chapter3
Chapter3Kamran
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYRajeshkumar Reddy
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeksAashutoshChhedavi
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingAniket Patne
 
C and C++ Industrial Training Jalandhar
C and C++ Industrial Training JalandharC and C++ Industrial Training Jalandhar
C and C++ Industrial Training JalandharDreamtech Labs
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training reportRaushan Pandey
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit orderMalikireddy Bramhananda Reddy
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 

What's hot (20)

C notes
C notesC notes
C notes
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
C basics
C   basicsC   basics
C basics
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
C programming
C programmingC programming
C programming
 
Chapter3
Chapter3Chapter3
Chapter3
 
# And ## operators in c
# And ## operators in c# And ## operators in c
# And ## operators in c
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
Apa style-1 (1)
Apa style-1 (1)Apa style-1 (1)
Apa style-1 (1)
 
C programming
C programmingC programming
C programming
 
C language introduction
C language introduction C language introduction
C language introduction
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C language
C languageC language
C language
 
C and C++ Industrial Training Jalandhar
C and C++ Industrial Training JalandharC and C++ Industrial Training Jalandhar
C and C++ Industrial Training Jalandhar
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 

Viewers also liked

Database management systems components
Database management systems componentsDatabase management systems components
Database management systems componentsmuhammad bilal
 
L8 components and properties of dbms
L8  components and properties of dbmsL8  components and properties of dbms
L8 components and properties of dbmsRushdi Shams
 
Database Management system
Database Management systemDatabase Management system
Database Management systemVijay Thorat
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Jargalsaikhan Alyeksandr
 

Viewers also liked (6)

Database management systems components
Database management systems componentsDatabase management systems components
Database management systems components
 
L8 components and properties of dbms
L8  components and properties of dbmsL8  components and properties of dbms
L8 components and properties of dbms
 
Database Management system
Database Management systemDatabase Management system
Database Management system
 
Databases: Normalisation
Databases: NormalisationDatabases: Normalisation
Databases: Normalisation
 
Network topology.ppt
Network topology.pptNetwork topology.ppt
Network topology.ppt
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)
 

Similar to C fundamentals

Similar to C fundamentals (20)

C prog ppt
C prog pptC prog ppt
C prog ppt
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
C language
C language C language
C language
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Introduction to C Programming - I
Introduction to C Programming - I Introduction to C Programming - I
Introduction to C Programming - I
 
C programming
C programmingC programming
C programming
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
What is turbo c and how it works
What is turbo c and how it worksWhat is turbo c and how it works
What is turbo c and how it works
 
Basics of C porgramming
Basics of C porgrammingBasics of C porgramming
Basics of C porgramming
 
C programming
C programmingC programming
C programming
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
Basic c
Basic cBasic c
Basic c
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 

More from Vikash Dhal

Control structuresin c
Control structuresin cControl structuresin c
Control structuresin cVikash Dhal
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesVikash Dhal
 
Implementation of strassens
Implementation of  strassensImplementation of  strassens
Implementation of strassensVikash Dhal
 
Packet switching
Packet switchingPacket switching
Packet switchingVikash Dhal
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++Vikash Dhal
 
File handling in c
File handling in c File handling in c
File handling in c Vikash Dhal
 

More from Vikash Dhal (7)

Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
Implementation of strassens
Implementation of  strassensImplementation of  strassens
Implementation of strassens
 
Packet switching
Packet switchingPacket switching
Packet switching
 
Raid
RaidRaid
Raid
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++
 
File handling in c
File handling in c File handling in c
File handling in c
 

Recently uploaded

GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 

Recently uploaded (20)

GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 

C fundamentals

  • 1. Fundamentals of C Programming Language and Dept. of CS&E nad IT, DBCET, Guwahati1 Basic Input / Output Functions
  • 2. Fundamentals of C and Input/Output Content: History of C Why C? C Development Environment C Program Structure Basic Data Types Dept. of CS&E nad IT, DBCET, Guwahati2 Basic Data Types Input/Output function Common Programming Error
  • 3. History of C In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the publication of The C Programming Language by Kernighan & Ritchie caused a revolution in the computing world In 1983, the American National Standards Institute (ANSI) Dept. of CS&E nad IT, DBCET, Guwahati3 In 1983, the American National Standards Institute (ANSI) established a committee to provide a modern, comprehensive definition of C.The resulting definition, the ANSI standard, or "ANSI C", was completed late 1988.
  • 4. History of C [contd..] Evolved from two previous languages BCPL , B BCPL (Basic Combined Programming Language) used for writing OS & compilers B used for creating early versions of UNIX OS Dept. of CS&E nad IT, DBCET, Guwahati4 B used for creating early versions of UNIX OS
  • 5. Why C Still Useful? C provides: Efficiency, high performance and high quality s/ws flexibility and power many high-level and low-level operations middle level Stability and small size code Provide functionality through rich set of function libraries Gateway for other professional languages like C C++ Java Dept. of CS&E nad IT, DBCET, Guwahati5 Gateway for other professional languages like C C++ Java C is used: System software Compilers, Editors, embedded systems data compression, graphics and computational geometry, utility programs databases, operating systems, device drivers, system level routines Also used in application programs
  • 6. C Development Environment DiskPhase 2 : Preprocessor program processes the code. Preprocessor EditorPhase 1 : Program is created using the Editor and stored on Disk. Disk Dept. of CS&E nad IT, DBCET, Guwahati6 code. DiskCompilerPhase 3 : Compiler creates object code and stores it on Disk. DiskLinkerPhase 4 : Linker links object code with libraries, creates a.out and stores it on Disk
  • 7. C Development Environment cont LoaderPhase 5 : : . Primary Memory Loader puts Program in Memory Dept. of CS&E nad IT, DBCET, Guwahati7 . C P U (execute)Phase 6 : : . Primary Memory CPU takes each instruction and executes it, storing new data values as the program executes.
  • 8. Dept. of CS&E nad IT, DBCET, Guwahati8 Entering, translating, and running a High-Level Language Program
  • 9. C Program Structure An example of simple program in C #include <stdio.h> void main(void) { Dept. of CS&E nad IT, DBCET, Guwahati9 { printf(“Welcome to Programmingn”); printf(“This is my first program in C language”); }
  • 10. The output The previous program will produce the following output on your screen Welcome to Programming This is my first program in C language Dept. of CS&E nad IT, DBCET, Guwahati10 This is my first program in C language
  • 11. Preprocessor directives A C program line begins with # provides an instruction to the C preprocessor (built into a C Compiler) It is executed before the actual compilation is done. It causes the preprocessor to include a copy of the header file at that point of code. Dept. of CS&E nad IT, DBCET, Guwahati11 In our example (#include<stdio.h>) identifies the header file for standard input and output needed by the printf(). Angle brackets indicate that the file is to be found in the usual place, which is system dependent.
  • 12. Function main Identify the start of the program Every C program has a main ( ) 'main' is a C keyword. We must not use it for any other variable. 4 common ways of main declaration Dept. of CS&E nad IT, DBCET, Guwahati12 4 common ways of main declaration int main(void) { return 0; } void main(void) { } main(void) { } main( ) { }
  • 13. The curly braces { } Identify a segment / body of a program The start and end of a function The start and end of the selection or repetition block. Since the opening brace indicates the start of a segment with the closing brace indicating the end of a segment, there must be just as many opening braces as Dept. of CS&E nad IT, DBCET, Guwahati13 with the closing brace indicating the end of a segment, there must be just as many opening braces as closing braces (this is a common mistake of beginners)
  • 14. Statement A specification of an action to be taken by the computer as the program executes. Each statement in C needs to be terminated with semicolon (;) Example: #include <stdio.h> Dept. of CS&E nad IT, DBCET, Guwahati14 #include <stdio.h> void main(void) { printf(“I love programmingn”); printf(“You will love it too once ”); printf(“you know the trickn”); } statement statement statement
  • 15. Statement cont… Statement has two parts : Declaration The part of the program that tells the compiler the names of memory cells in a program Executable statements Program lines that are converted to machine language instructions and executed by the computer Dept. of CS&E nad IT, DBCET, Guwahati15 and executed by the computer
  • 16. C program skeleton In short, the basic skeleton of a C program looks like this: #include <stdio.h> void main(void) { Preprocessor directives Function main Start of segment Dept. of CS&E nad IT, DBCET, Guwahati16 statement(s); } End of segment
  • 17. Identifiers Words used to represent certain program entities (variables, function names, etc). Example: int my_name; my_name is an identifier used as a program variable void CalculateTotal(int value) Dept. of CS&E nad IT, DBCET, Guwahati17 void CalculateTotal(int value) CalculateTotal is an identifier used as a function name
  • 18. Rules for naming identifiers Rules Example Can contain a mix of characters and numbers. However it cannot start with a number H2o First character must be a letter or underscore Number1; _area Can be of mixed cases including underscore XsquAre Dept. of CS&E nad IT, DBCET, Guwahati18 Can be of mixed cases including underscore character XsquAre my_num Cannot contain any arithmetic operators R*S+T or any other punctuation marks #@x%!! Cannot be a C keyword/reserved word struct; printf; Cannot contain a space My height identifiers are case sensitive Tax != tax
  • 19. Variables Variable a name associated with a memory cell whose value can change Variable Declaration: specifies the type of a variable Example: int num; Dept. of CS&E nad IT, DBCET, Guwahati19 Variable Definition: assigning a value to the declared variable Example: num = 5;
  • 20. Basic Data Types There are 4 basic data types : int float double char int Dept. of CS&E nad IT, DBCET, Guwahati20 int used to declare numeric program variables of integer type whole numbers, positive and negative keyword: int int number; number = 12;
  • 21. Basic Data Types cont… float fractional parts, positive and negative keyword: float float height; height = 1.72; double Dept. of CS&E nad IT, DBCET, Guwahati21 double used to declare floating point variable of higher precision or higher range of numbers exponential numbers, positive and negative keyword: double double valuebig; valuebig = 12E-3;
  • 22. Basic Data Types cont… char equivalent to ‘letters’ in English language Example of characters: Numeric digits: 0 - 9 Lowercase/uppercase letters: a - z and A - Z Space (blank) Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc Dept. of CS&E nad IT, DBCET, Guwahati22 Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc single character keyword: char char my_letter; my_letter = 'U'; The declared character must be enclosed within a single quote!
  • 23. Constants Entities that appear in the program code as fixed values. Any attempt to modify a CONSTANT will result in error. 4 types of constants: Integer constants Positive or negative whole numbers with no fractional part Example: const int MAX_NUM = 10; Dept. of CS&E nad IT, DBCET, Guwahati23 const int MAX_NUM = 10; const int MIN_NUM = -90; Floating-point constants (float or double) Positive or negative decimal numbers with an integer part, a decimal point and a fractional part Example: const doubleVAL = 0.5877e2; (stands for 0.5877 x 102)
  • 24. Constants cont… Character constants A character enclosed in a single quotation mark Example: const char letter = ‘n’; const char number = ‘1’; printf(“%c”,‘S’); Output would be: S Dept. of CS&E nad IT, DBCET, Guwahati24 Output would be: S Enumeration Values are given as a list Example: enum Language { Malay, English, Arabic };
  • 25. Constant example – volume of a cone #include <stdio.h> void main(void) { const double pi = 3.142; double height, radius, base, volume; printf(“Enter the height and radius of the cone:”); Dept. of CS&E nad IT, DBCET, Guwahati25 printf(“Enter the height and radius of the cone:”); scanf(“%lf %lf”,&height, &radius); base = pi * radius * radius; volume = (1.0/3.0) * base * height; printf(“nThe volume of a cone is %lf ”, volume); }
  • 26. #define You may also associate constant using #define preprocessor directive #include <stdio.h> #define pi 3.142 void main(void) { double height, radius, base, volume; Dept. of CS&E nad IT, DBCET, Guwahati26 printf(“Enter the height and radius of the cone:”); scanf(“%lf %lf”,&height,&radius); base = pi * radius * radius; volume = (1.0/3.0) * base * height; printf(“nThe volume of a cone is %lf ”, volume); }
  • 27. Input/Output Operations Input operation an instruction that copies data from an input device into memory Output operation an instruction that displays information stored in memory to Dept. of CS&E nad IT, DBCET, Guwahati27 an instruction that displays information stored in memory to the output devices (such as the monitor screen)
  • 28. Input/Output Functions A C function that performs an input or output operation A few functions that are pre-defined in the header file stdio.h such as : printf() scanf() Dept. of CS&E nad IT, DBCET, Guwahati28 getchar() & putchar()
  • 29. The printf function Used to send data to the standard output (usually the monitor) to be printed according to specific format. General format: printf(“string literal”); Dept. of CS&E nad IT, DBCET, Guwahati29 printf(“string literal”); A sequence of any number of characters surrounded by double quotation marks. printf(“format string”, variables); Format string is a combination of text, conversion specifier and escape sequence.
  • 30. The printf function cont… Example: printf(“Thank you”); printf (“Total sum is: %dn”, sum); %d is a placeholder (conversion specifier) marks the display position for a type integer variable n is an escape sequence Dept. of CS&E nad IT, DBCET, Guwahati30 n is an escape sequence moves the cursor to the new line
  • 31. Escape Sequence Escape Sequence Effect a Beep sound b Backspace f Formfeed (for printing) n New line r Carriage return Dept. of CS&E nad IT, DBCET, Guwahati31 r Carriage return t Tab v Vertical tab Backslash ” “ sign o Octal decimal x Hexa decimal 0 NULL
  • 32. Placeholder / Conversion Specifier No Conversion Specifier Output Type Output Example 1 %d Signed decimal integer 76 2 %i Signed decimal integer 76 3 %o Unsigned octal integer 134 4 %u Unsigned decimal integer 76 5 %x Unsigned hexadecimal (small letter) 9c 6 %X Unsigned hexadecimal (capital letter) 9C Dept. of CS&E nad IT, DBCET, Guwahati32 6 %X Unsigned hexadecimal (capital letter) 9C 7 %f Integer including decimal point 76.0000 8 %e Signed floating point (using e notation) 7.6000e+01 9 %E Signed floating point (using E notation) 7.6000E+01 10 %g The shorter between %f and %e 76 11 %G The shorter between %f and %E 76 12 %c Character ‘7’ 13 %s String “76”
  • 33. The scanf function Read data from the standard input device (usually keyboard) and store it in a variable. General format: scanf(“Format string”, &variable); Notice ampersand (&) operator : Dept. of CS&E nad IT, DBCET, Guwahati33 Notice ampersand (&) operator : C address of operator it passes the address of the variable instead of the variable itself tells the scanf() where to find the variable to store the new value
  • 34. The scanf function cont… Example : int age; printf(“Enter your age:“); scanf(“%d”, &age); Common Conversion Identifier used in printf and Dept. of CS&E nad IT, DBCET, Guwahati34 Common Conversion Identifier used in printf and scanf functions. printf scanf int %d %d float %f %f double %f %lf char %c %c string %s %s
  • 35. The scanf function cont… If you want the user to enter more than one value, you serialise the inputs. Example: float height, weight; Dept. of CS&E nad IT, DBCET, Guwahati35 printf(“Please enter your height and weight:”); scanf(“%f%f”, &height, &weight);
  • 36. getchar() and putchar() getchar() - read a character from standard input putchar() - write a character to standard output Example: #include <stdio.h> void main(void) Dept. of CS&E nad IT, DBCET, Guwahati36 void main(void) { char my_char; printf(“Please type a character: ”); my_char = getchar(); printf(“nYou have typed this character: ”); putchar(my_char); }
  • 37. getchar() and putchar() cont Alternatively, you can write the previous code using normal scanf and %c placeholder. Example #include <stdio.h> void main(void) Dept. of CS&E nad IT, DBCET, Guwahati37 void main(void) { char my_char; printf(“Please type a character: ”); scanf(“%c”,&my_char); printf(“nYou have typed this character: %c ”, my_char); }
  • 38. Few notes on C program… C is case-sensitive Word, word,WorD,WORD,WOrD, worD, etc are all different variables / expressions Eg. sum = 23 + 7 What is the value of Sum after this addition ? Dept. of CS&E nad IT, DBCET, Guwahati38 Comments (remember 'Documentation') are inserted into the code using /* to start and */ to end a comment Some compiler support comments starting with ‘//’ Provides supplementary information but is ignored by the preprocessor and compiler /* This is a comment */ // This program was written by me
  • 39. Few notes on C program cont… ReservedWords Keywords that identify language entities such as statements, data types, language attributes, etc. Have special meaning to the compiler, cannot be used as identifiers (variable, function name) in our program. Should be typed in lowercase. Dept. of CS&E nad IT, DBCET, Guwahati39 Should be typed in lowercase. Example: const, double, int, main, void,printf, while, for, else (etc..)
  • 40. Few notes on C program cont… Punctuators (separators) Symbols used to separate different parts of the C program. These punctuators include: [ ] ( ) { } , ;“: * # Usage example: Dept. of CS&E nad IT, DBCET, Guwahati40 void main (void) { int num = 10; printf (“%d”, num); }
  • 41. Few notes on C program cont… Operators Tokens that result in some kind of computation or action when applied to variables or other elements in an expression. Example of operators: * + = - / Dept. of CS&E nad IT, DBCET, Guwahati41 Usage example: result = total1 + total2;
  • 42. Common Programming Errors Debugging Process removing errors from a program Three (3) kinds of errors : Syntax Error Dept. of CS&E nad IT, DBCET, Guwahati42 Syntax Error a violation of the C grammar rules, detected during program translation (compilation). statement cannot be translated and program cannot be executed
  • 43. Common Programming Errors cont… Run-time errors An attempt to perform an invalid operation, detected during program execution. Occurs when the program directs the computer to perform an illegal operation, such as dividing a number by zero. Dept. of CS&E nad IT, DBCET, Guwahati43 number by zero. The computer will stop executing the program, and displays a diagnostic message indicates the line where the error was detected
  • 44. Common Programming Errors cont… Logic Error/Design Error An error caused by following an incorrect algorithm Very difficult to detect - it does not cause run-time error and does not display message errors. The only sign of logic error – incorrect program output Can be detected by testing the program thoroughly,comparing its output to calculated results To prevent – carefully desk checking the algorithm and written Dept. of CS&E nad IT, DBCET, Guwahati44 To prevent – carefully desk checking the algorithm and written program before you actually type it
  • 45. Summary You have learned the following items: History of C and related topics Environment of C language and C programming C language elements Preprocessor directives, curly braces, main (), semicolon, comments, double quotes Dept. of CS&E nad IT, DBCET, Guwahati45 double quotes 4 basics data type and brief explanation on variable 6 tokens : reserved word, identifier, constant, string literal, punctuators / separators and operators. printf, scanf, getchar and putchar Usage of modifiers : placeholder & escape sequence Common programming errors : syntax error, run-time error and logic error