SlideShare a Scribd company logo
1 of 35
Programming With C
Fundamentals of ‘C’ including
data types, operators and I/O
statements
Gagan Deep
Founder & Director
Rozy Computech Services
Kurukshetra-136119
M- 9416011599
Email – rozygag@yahoo.com
www.rozyph.com
Contents of Discussion
• Language & Programming Language
• About C
• Character Set, Identifiers & Statements
• Data Types
• Operators
• Input Output Functions
• Programming Examples
Language
• Language is a way of Communication Between
Two like Hindi, English, Punjabi, Marathi,
Tamil etc.
• If we want to communicate other then our own
languages then we can communicate in either of
two ways
- Either Learn
- Use Translator
Programming Language
• Way of Communication between Human and
Computer like Machine language, Assembly
Language, High Level Language.
• Machine Language and Assembly Languages are
low level languages because these don’t work like
our own languages.
• High level languages(HLL) works like our own
languages like Hindi, English and others that’s
why these are known as HLL.
About C
• C is a Programming Language
• C Language is a High Level Language (because it
works like natural language). Here we uses
English like statements.
• C Language also have a properties of low level
languages
• That’s why some of us says – This is Middle
Level Language.
About C
• C is a general purpose programming language.
• C was originally designed for and implemented
on the UNIX operating system on the DEC PDP-
11, by Dennis Ritchie.
• C is a case sensitive language A≠ a
Character Set / Alphabets
• First Thing we learned in any language is
Alphabets – Similarly in Programming Languages
is Character Set.
• C character Set includes alphabets like a-z, A-Z,
Digits like 0-9, special symbols like !, @, #, $, %,
…….-, + etc., and some other characters which
are not available on keyboard <=, >=, !=, == etc.
• Print Characters- which are known as Escape
sequences like ‘n’, ‘t’, ‘b’ etc…
Words
• Second thing we always learn in any language are
words. Similarly we learn here in C. Here we say
words as Identifiers and Reserve words.
• Identifier Gagan, Rajesh, Saminder, Meenu, etc.
are our names which identifies us, and some other
names are like Table, chair, Fan, Tube which we
always we are using for some objects.
• First Type of Identifiers are known as Variable in
any Language or we can say in C and second type of
names are known as Constants.
• Some other words are known as Standard words
like min, max etc.
Rules for Naming Identifiers
• First Character is Letter not digit
• Second character it may be letter or digit
• Special characters (other then letters or digits)
are not allowed Except underscore(_)
• Length of Identifiers 8, 31 etc.
Type of Identifiers – Data Type
• Like we have our Gender Males / Females. Similarly
in each language we have some types of identifier
known as Data types.
• What data type does is categorize data.
• These basic categorizations or data types are
integer(int),
• Real(float),
• Character (char)
• char – 1 byte - -128 to 127
• Character can declare as
char c;
• int – 2 bytes - Range (-32768 to 32767)
• Integer can declare as
int a;
• float – 4 bytes - 3.4X10-38 to 3.4X1038
• Real can declare as
float f;
Why int’s range is -32768 to 32767 ?
Integer Representation
• Most of the computers use 2 bytes to store an
integer.
• The left most bit, out of sixteen bits, is used to
indicate the sign of the integer and is called Sign
bit.
• The other 15 bits are used to store the given
integer, a 0 in the sign bit position indicates a
positive integer and 1 in this position means the
integer stored is negative.
Integer Representation
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0/1
Sign
Bit
15 bits for Number representation
Maximum Number
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
+215-1 = 32767
Minimum Number
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
-215 = -32768
Unsigned Numbers are numbers without sign i.e. First bit is used for number itself.
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Range is 0 to 216 -1 i.e. 0 to 65535
If we want bigger number then the
ranges defined.
• char – strings
String is collection of character
• int – short, long, unsigned, unsigned long
Short is of 1 byte.
Long is of 4 bytes(double precession(size))
• float - double
Double is of 8 Bytes
Constants
• int – Decimal, Octal, Hexadecimal
• Decimal int – 77 equals 77
• Octal int – 077 equals 63
• Hexadecimal int – 0x77 equals 119
• Unsigned int – 45678U
• Unsigned long – 243567849UL
• Float –
• Char - ‘a’
• String – “Rozy” ,
Sentences / Statements
• Third thing we learn in any language are sentences,
here in programming these are known as statements.
• Statements are the instructions given to the
computer to perform any kind of action.
• Statements form the smallest executable unit within
a C++ program.
• As sentences terminated by some full stop(., I),
similarly, Statements are terminated with a
semicolon (;).
Types of Statements
• Simple Statements
• Compound Statements
• Control Statements
Simple Statement – Single statement. The
simplest statement is the empty, or null statement.
e.g.
; // it is a null statement.
Examples of simple statement are as
x=y; x=x+y; scanf(“%d”, &ajay);
printf(“%d”, ajay);
• Compound Statement – paragraph (Block) A
compound statement in C++ is a sequence of
statements enclosed by a pair of braces ({}). e.g.,
{ statement 1;
statement 2; },
A compound statement is treated as a single unit or
statement.
• Control Statements – which controls flow of
statements like decision/ branching and loops
Operators
• Operators are tokens that trigger some computation
when applied to variable and other objects in an
expression. Classifications of Operators are
Depending upon the number of operands we have :
• Unary operators : These operators require just 1
operand. e.g, - (minus sign), ++, --, sizeof etc.
• Binary operators: These operators take 2
operands. e.g. +, -, *, / , <, >, !=, <=
• Ternary operators: These operators take 3 operands,
e.g. Conditional operator (? : ) e.g. (A >B?5:6)
Operators by Operations
• Arithmetic Operators : Integer and Real
Integer : +,-, *, /, %
Real : +, -, *, /
• Relational Operators : <, >, <=, >=,
• Equality Operators : !=, ==
• Logical Operators : && (AND), ||(OR), !(NOT)
• Assignment Arithmetic Operators : +=, *=, /= etc.
e.g. a+=5 is equivalent to a=a+5. These are also
known as Compound Assignment or
Shorthand's
Operators by Operations
• Increment Operator
• Decrement Operators : Similarly pre and post
decrement operators e.g. - -a; and a- -;
Pre increment : ++a
++a means a = a +1
Pre means before execution of
statement e.g. If a=5;
Post increment : a++
a++ means a = a +1
Post means after execution of
statement e.g. If a=5;
printf(“%d”, a); //returns 5
printf(“%d”, ++a); //returns 6
printf(“%d”, a); //returns 6
printf(“%d”, a); //returns 5
printf(“%d”, a++); //returns 5
printf(“%d”, a); //returns 6
Hierarchy / Precedence of
Operators with their Associativity
Operators Category Operators Associativity
Unary Operators -, ++, - - , !, sizeof , (type) Right → Left (R→L)
Arithmetic * , / , %, Left → Right (L → R)
+ , -
Relational < , <=, >, >= L → R
Equality == , != L → R
Logical && L → R
|| L → R
Assignment =, +=, -=, *=, /=, %= R → L
Data Input and Output
• In C you can input/output using input and output
library function.
• Functions – User Defined and Library Function
• These I/O Library functions are getchar(), putchar(),
scanf(), printf(), gets() and puts().
• These six functions permits the transfer of information
between the computer and the standard I/O
devices(e.g. Keyboard, VDU etc.)
• An I/O fxs. Can be accessed from anywhere within the
program simply by writing the function name.
I/O Statements
• First we discuss about Single Character and
Strings I/O Functions
Single Character I/O
Functions are getchar()
and putchar ()
String I/O Functions are
gets() and puts()
char c;
Input statement like this
c = getchar();
Output statement like this
putchar( c );
char name[20];
Input statement like this
gets(name);
Output statement like this
puts(name);
scanf()
• With the help of scanf() we can enter any type of
data and mixed data. In general terms scanf()
function is written as
scanf( control string, arg1, arg2, arg3…, argn);
• Control String consists of individual groups of
characters, with one character group for each
input data item.
• Each character group must begin with a
percent(%) sign and followed by conversion
character which indicates the type of
corresponding data item.
Commonly used conversion characters for data
input are
• c for single character,
• d is for decimal integer,
• e for floating point value,
• f for floating point value,
• l is for long etc….
• The arguments are written as variables, arrays,
whose types match the corresponding character
group in the control string.
• Each variable must be preceded by an ampersand
(&).
• Array name should not begin with &.
Examples
char name[20];
int roll; float marks;
scanf(“ %s %d %f”, name, &roll, &marks);
• Formatted scanf() function
int a,b,c;
scanf(“%3d, %3d %3d”, &a, &b, &c);
In the above statement all a,b and c can take
maximum of 3 digits.
printf()
• It is similar to input function scanf(), except that
its purpose is to display data rather than to enter
it into the computer.
• Also there is no ampersand (&) symbol before
args.
printf(“ %s n %d n %f”, name, roll, marks);
Formatted printf() function
• example
int a,b,c;
printf(“%3d, %3d %3d”, a, b, c);
• In the above statement all a,b and c can display
minimum of 3 digits or spaces instead of digits.
Structure of C Program
# include < header file> // # is pre-processor
directive
#define x 5; //symbolic constant
int a, b; //global variable declaration
int fxn(); // function declaration
main()
{ int i,j,k; // local variable declaration
Input statements;
Process;
Output Statements; }
Program 1
# include < stdio.h>
main( ) // by default main function is int type
{ int a=5,b=6,c;
c=a+b;
printf(“The sum is = %d”, c);
}
Program 2
# include < stdio.h>
main( )
{
int a,b,c;
scanf(“%d, %d”, &a, &b);
c=a+b;
printf(“The sum is = %d”, c);
}
Program 3
# include < stdio.h>
void main()
/* void is data type which says function should not
return any value*/
{ int a,b;
scanf(“%d, %d”, &a, &b);
printf(“The sum is = %d”, a+b);
}
Program 4
# include < stdio.h>
#include <conio.h>
void main()
{
int a,b;
clrscr();
printf(“Please enter the value of a & b”);
scanf(“%3d, %3d”, &a, &b);
printf(“The sum is = %4d”, a+b); }
C Programming Fundamentals

More Related Content

What's hot

Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingEelco Visser
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java Ahmad Idrees
 
Lecture 02 lexical analysis
Lecture 02 lexical analysisLecture 02 lexical analysis
Lecture 02 lexical analysisIffat Anjum
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptApoorv Diwan
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Aman Sharma
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysisIffat Anjum
 
JavaScript – ECMAScript Basics By Satyen
JavaScript – ECMAScript Basics By SatyenJavaScript – ECMAScript Basics By Satyen
JavaScript – ECMAScript Basics By SatyenSatyen Pandya
 
Introduction to C Programming - R.D.Sivakumar
Introduction to C Programming -  R.D.SivakumarIntroduction to C Programming -  R.D.Sivakumar
Introduction to C Programming - R.D.SivakumarSivakumar R D .
 
DATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.netDATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.netSireesh K
 

What's hot (20)

Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
 
Chap 1 and 2
Chap 1 and 2Chap 1 and 2
Chap 1 and 2
 
Lexical analysis
Lexical analysisLexical analysis
Lexical analysis
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Data type
Data typeData type
Data type
 
Lecture 02 lexical analysis
Lecture 02 lexical analysisLecture 02 lexical analysis
Lecture 02 lexical analysis
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Data types
Data typesData types
Data types
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Python Data Types
Python Data TypesPython Data Types
Python Data Types
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
 
Token and operators
Token and operatorsToken and operators
Token and operators
 
Introduction
IntroductionIntroduction
Introduction
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysis
 
JavaScript – ECMAScript Basics By Satyen
JavaScript – ECMAScript Basics By SatyenJavaScript – ECMAScript Basics By Satyen
JavaScript – ECMAScript Basics By Satyen
 
Introduction to C Programming - R.D.Sivakumar
Introduction to C Programming -  R.D.SivakumarIntroduction to C Programming -  R.D.Sivakumar
Introduction to C Programming - R.D.Sivakumar
 
DATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.netDATATYPE IN C# CSHARP.net
DATATYPE IN C# CSHARP.net
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 

Viewers also liked

Software Project Planning V
Software Project Planning VSoftware Project Planning V
Software Project Planning VGagan Deep
 
Software Project Planning IV
Software Project Planning IVSoftware Project Planning IV
Software Project Planning IVGagan Deep
 
Software Project Planning III
Software Project Planning IIISoftware Project Planning III
Software Project Planning IIIGagan Deep
 
Software Engineering
Software Engineering Software Engineering
Software Engineering Gagan Deep
 
Fundamentals of Neural Networks
Fundamentals of Neural NetworksFundamentals of Neural Networks
Fundamentals of Neural NetworksGagan Deep
 
Normalization 1
Normalization 1Normalization 1
Normalization 1Gagan Deep
 
Normalization i i
Normalization   i iNormalization   i i
Normalization i iGagan Deep
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareGagan Deep
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial IntelligenceGagan Deep
 
SQL – A Tutorial I
SQL – A Tutorial  ISQL – A Tutorial  I
SQL – A Tutorial IGagan Deep
 
Information System and MIS
Information System and MISInformation System and MIS
Information System and MISGagan Deep
 
System Analysis & Design - 2
System Analysis & Design - 2System Analysis & Design - 2
System Analysis & Design - 2Gagan Deep
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : ArraysGagan Deep
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manualmaha tce
 
Sql queries interview questions
Sql queries interview questionsSql queries interview questions
Sql queries interview questionsPyadav010186
 
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUEducation
 

Viewers also liked (20)

Software Project Planning V
Software Project Planning VSoftware Project Planning V
Software Project Planning V
 
Software Project Planning IV
Software Project Planning IVSoftware Project Planning IV
Software Project Planning IV
 
Software Project Planning III
Software Project Planning IIISoftware Project Planning III
Software Project Planning III
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
 
Fundamentals of Neural Networks
Fundamentals of Neural NetworksFundamentals of Neural Networks
Fundamentals of Neural Networks
 
Normalization 1
Normalization 1Normalization 1
Normalization 1
 
Normalization i i
Normalization   i iNormalization   i i
Normalization i i
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 
SQL – A Tutorial I
SQL – A Tutorial  ISQL – A Tutorial  I
SQL – A Tutorial I
 
Information System and MIS
Information System and MISInformation System and MIS
Information System and MIS
 
Assembly language programming
Assembly language programmingAssembly language programming
Assembly language programming
 
System Analysis & Design - 2
System Analysis & Design - 2System Analysis & Design - 2
System Analysis & Design - 2
 
Number system
Number systemNumber system
Number system
 
Dbms viva questions
Dbms viva questionsDbms viva questions
Dbms viva questions
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manual
 
Sql queries interview questions
Sql queries interview questionsSql queries interview questions
Sql queries interview questions
 
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YU
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
 

Similar to C Programming Fundamentals

2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++Aahwini Esware gowda
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageDr.Florence Dayana
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingz9819898203
 
20BCT23 – PYTHON PROGRAMMING.pptx
20BCT23 – PYTHON PROGRAMMING.pptx20BCT23 – PYTHON PROGRAMMING.pptx
20BCT23 – PYTHON PROGRAMMING.pptxgokilabrindha
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++K Durga Prasad
 
Programming in c
Programming in cProgramming in c
Programming in cvineet4523
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.pptTanuGohel
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.pptMEHALAS3
 
Basics of C (1).ppt
Basics of C (1).pptBasics of C (1).ppt
Basics of C (1).pptSteveIrwin25
 
C programming basic pdf.ppt
C programming basic pdf.pptC programming basic pdf.ppt
C programming basic pdf.pptKauserJahan6
 
Basics of C--C Basics------------------.ppt
Basics of C--C Basics------------------.pptBasics of C--C Basics------------------.ppt
Basics of C--C Basics------------------.pptRavi Chandra Medisetty
 

Similar to C Programming Fundamentals (20)

2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
 
20BCT23 – PYTHON PROGRAMMING.pptx
20BCT23 – PYTHON PROGRAMMING.pptx20BCT23 – PYTHON PROGRAMMING.pptx
20BCT23 – PYTHON PROGRAMMING.pptx
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
fundamentals of c
fundamentals of cfundamentals of c
fundamentals of c
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Chapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B KuteChapter 01 Introduction to Java by Tushar B Kute
Chapter 01 Introduction to Java by Tushar B Kute
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Funa-C.ppt
Funa-C.pptFuna-C.ppt
Funa-C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C (1).ppt
Basics of C (1).pptBasics of C (1).ppt
Basics of C (1).ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
C programming basic pdf.ppt
C programming basic pdf.pptC programming basic pdf.ppt
C programming basic pdf.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C--C Basics------------------.ppt
Basics of C--C Basics------------------.pptBasics of C--C Basics------------------.ppt
Basics of C--C Basics------------------.ppt
 

More from Gagan Deep

Software Project Planning II
Software Project Planning IISoftware Project Planning II
Software Project Planning IIGagan Deep
 
Software Project Planning 1
Software Project Planning 1Software Project Planning 1
Software Project Planning 1Gagan Deep
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshareGagan Deep
 
System Analysis & Design - I
System Analysis & Design - ISystem Analysis & Design - I
System Analysis & Design - IGagan Deep
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebraGagan Deep
 
Plsql overview
Plsql overviewPlsql overview
Plsql overviewGagan Deep
 

More from Gagan Deep (6)

Software Project Planning II
Software Project Planning IISoftware Project Planning II
Software Project Planning II
 
Software Project Planning 1
Software Project Planning 1Software Project Planning 1
Software Project Planning 1
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
System Analysis & Design - I
System Analysis & Design - ISystem Analysis & Design - I
System Analysis & Design - I
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebra
 
Plsql overview
Plsql overviewPlsql overview
Plsql overview
 

Recently uploaded

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 

Recently uploaded (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 

C Programming Fundamentals

  • 1. Programming With C Fundamentals of ‘C’ including data types, operators and I/O statements Gagan Deep Founder & Director Rozy Computech Services Kurukshetra-136119 M- 9416011599 Email – rozygag@yahoo.com www.rozyph.com
  • 2. Contents of Discussion • Language & Programming Language • About C • Character Set, Identifiers & Statements • Data Types • Operators • Input Output Functions • Programming Examples
  • 3. Language • Language is a way of Communication Between Two like Hindi, English, Punjabi, Marathi, Tamil etc. • If we want to communicate other then our own languages then we can communicate in either of two ways - Either Learn - Use Translator
  • 4. Programming Language • Way of Communication between Human and Computer like Machine language, Assembly Language, High Level Language. • Machine Language and Assembly Languages are low level languages because these don’t work like our own languages. • High level languages(HLL) works like our own languages like Hindi, English and others that’s why these are known as HLL.
  • 5. About C • C is a Programming Language • C Language is a High Level Language (because it works like natural language). Here we uses English like statements. • C Language also have a properties of low level languages • That’s why some of us says – This is Middle Level Language.
  • 6. About C • C is a general purpose programming language. • C was originally designed for and implemented on the UNIX operating system on the DEC PDP- 11, by Dennis Ritchie. • C is a case sensitive language A≠ a
  • 7. Character Set / Alphabets • First Thing we learned in any language is Alphabets – Similarly in Programming Languages is Character Set. • C character Set includes alphabets like a-z, A-Z, Digits like 0-9, special symbols like !, @, #, $, %, …….-, + etc., and some other characters which are not available on keyboard <=, >=, !=, == etc. • Print Characters- which are known as Escape sequences like ‘n’, ‘t’, ‘b’ etc…
  • 8. Words • Second thing we always learn in any language are words. Similarly we learn here in C. Here we say words as Identifiers and Reserve words. • Identifier Gagan, Rajesh, Saminder, Meenu, etc. are our names which identifies us, and some other names are like Table, chair, Fan, Tube which we always we are using for some objects. • First Type of Identifiers are known as Variable in any Language or we can say in C and second type of names are known as Constants. • Some other words are known as Standard words like min, max etc.
  • 9. Rules for Naming Identifiers • First Character is Letter not digit • Second character it may be letter or digit • Special characters (other then letters or digits) are not allowed Except underscore(_) • Length of Identifiers 8, 31 etc.
  • 10. Type of Identifiers – Data Type • Like we have our Gender Males / Females. Similarly in each language we have some types of identifier known as Data types. • What data type does is categorize data. • These basic categorizations or data types are integer(int), • Real(float), • Character (char)
  • 11. • char – 1 byte - -128 to 127 • Character can declare as char c; • int – 2 bytes - Range (-32768 to 32767) • Integer can declare as int a; • float – 4 bytes - 3.4X10-38 to 3.4X1038 • Real can declare as float f;
  • 12. Why int’s range is -32768 to 32767 ? Integer Representation • Most of the computers use 2 bytes to store an integer. • The left most bit, out of sixteen bits, is used to indicate the sign of the integer and is called Sign bit. • The other 15 bits are used to store the given integer, a 0 in the sign bit position indicates a positive integer and 1 in this position means the integer stored is negative.
  • 13. Integer Representation 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0/1 Sign Bit 15 bits for Number representation Maximum Number 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +215-1 = 32767 Minimum Number 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -215 = -32768 Unsigned Numbers are numbers without sign i.e. First bit is used for number itself. 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Range is 0 to 216 -1 i.e. 0 to 65535
  • 14. If we want bigger number then the ranges defined. • char – strings String is collection of character • int – short, long, unsigned, unsigned long Short is of 1 byte. Long is of 4 bytes(double precession(size)) • float - double Double is of 8 Bytes
  • 15. Constants • int – Decimal, Octal, Hexadecimal • Decimal int – 77 equals 77 • Octal int – 077 equals 63 • Hexadecimal int – 0x77 equals 119 • Unsigned int – 45678U • Unsigned long – 243567849UL • Float – • Char - ‘a’ • String – “Rozy” ,
  • 16. Sentences / Statements • Third thing we learn in any language are sentences, here in programming these are known as statements. • Statements are the instructions given to the computer to perform any kind of action. • Statements form the smallest executable unit within a C++ program. • As sentences terminated by some full stop(., I), similarly, Statements are terminated with a semicolon (;).
  • 17. Types of Statements • Simple Statements • Compound Statements • Control Statements Simple Statement – Single statement. The simplest statement is the empty, or null statement. e.g. ; // it is a null statement. Examples of simple statement are as x=y; x=x+y; scanf(“%d”, &ajay); printf(“%d”, ajay);
  • 18. • Compound Statement – paragraph (Block) A compound statement in C++ is a sequence of statements enclosed by a pair of braces ({}). e.g., { statement 1; statement 2; }, A compound statement is treated as a single unit or statement. • Control Statements – which controls flow of statements like decision/ branching and loops
  • 19. Operators • Operators are tokens that trigger some computation when applied to variable and other objects in an expression. Classifications of Operators are Depending upon the number of operands we have : • Unary operators : These operators require just 1 operand. e.g, - (minus sign), ++, --, sizeof etc. • Binary operators: These operators take 2 operands. e.g. +, -, *, / , <, >, !=, <= • Ternary operators: These operators take 3 operands, e.g. Conditional operator (? : ) e.g. (A >B?5:6)
  • 20. Operators by Operations • Arithmetic Operators : Integer and Real Integer : +,-, *, /, % Real : +, -, *, / • Relational Operators : <, >, <=, >=, • Equality Operators : !=, == • Logical Operators : && (AND), ||(OR), !(NOT) • Assignment Arithmetic Operators : +=, *=, /= etc. e.g. a+=5 is equivalent to a=a+5. These are also known as Compound Assignment or Shorthand's
  • 21. Operators by Operations • Increment Operator • Decrement Operators : Similarly pre and post decrement operators e.g. - -a; and a- -; Pre increment : ++a ++a means a = a +1 Pre means before execution of statement e.g. If a=5; Post increment : a++ a++ means a = a +1 Post means after execution of statement e.g. If a=5; printf(“%d”, a); //returns 5 printf(“%d”, ++a); //returns 6 printf(“%d”, a); //returns 6 printf(“%d”, a); //returns 5 printf(“%d”, a++); //returns 5 printf(“%d”, a); //returns 6
  • 22. Hierarchy / Precedence of Operators with their Associativity Operators Category Operators Associativity Unary Operators -, ++, - - , !, sizeof , (type) Right → Left (R→L) Arithmetic * , / , %, Left → Right (L → R) + , - Relational < , <=, >, >= L → R Equality == , != L → R Logical && L → R || L → R Assignment =, +=, -=, *=, /=, %= R → L
  • 23. Data Input and Output • In C you can input/output using input and output library function. • Functions – User Defined and Library Function • These I/O Library functions are getchar(), putchar(), scanf(), printf(), gets() and puts(). • These six functions permits the transfer of information between the computer and the standard I/O devices(e.g. Keyboard, VDU etc.) • An I/O fxs. Can be accessed from anywhere within the program simply by writing the function name.
  • 24. I/O Statements • First we discuss about Single Character and Strings I/O Functions Single Character I/O Functions are getchar() and putchar () String I/O Functions are gets() and puts() char c; Input statement like this c = getchar(); Output statement like this putchar( c ); char name[20]; Input statement like this gets(name); Output statement like this puts(name);
  • 25. scanf() • With the help of scanf() we can enter any type of data and mixed data. In general terms scanf() function is written as scanf( control string, arg1, arg2, arg3…, argn); • Control String consists of individual groups of characters, with one character group for each input data item. • Each character group must begin with a percent(%) sign and followed by conversion character which indicates the type of corresponding data item.
  • 26. Commonly used conversion characters for data input are • c for single character, • d is for decimal integer, • e for floating point value, • f for floating point value, • l is for long etc…. • The arguments are written as variables, arrays, whose types match the corresponding character group in the control string. • Each variable must be preceded by an ampersand (&). • Array name should not begin with &.
  • 27. Examples char name[20]; int roll; float marks; scanf(“ %s %d %f”, name, &roll, &marks); • Formatted scanf() function int a,b,c; scanf(“%3d, %3d %3d”, &a, &b, &c); In the above statement all a,b and c can take maximum of 3 digits.
  • 28. printf() • It is similar to input function scanf(), except that its purpose is to display data rather than to enter it into the computer. • Also there is no ampersand (&) symbol before args. printf(“ %s n %d n %f”, name, roll, marks);
  • 29. Formatted printf() function • example int a,b,c; printf(“%3d, %3d %3d”, a, b, c); • In the above statement all a,b and c can display minimum of 3 digits or spaces instead of digits.
  • 30. Structure of C Program # include < header file> // # is pre-processor directive #define x 5; //symbolic constant int a, b; //global variable declaration int fxn(); // function declaration main() { int i,j,k; // local variable declaration Input statements; Process; Output Statements; }
  • 31. Program 1 # include < stdio.h> main( ) // by default main function is int type { int a=5,b=6,c; c=a+b; printf(“The sum is = %d”, c); }
  • 32. Program 2 # include < stdio.h> main( ) { int a,b,c; scanf(“%d, %d”, &a, &b); c=a+b; printf(“The sum is = %d”, c); }
  • 33. Program 3 # include < stdio.h> void main() /* void is data type which says function should not return any value*/ { int a,b; scanf(“%d, %d”, &a, &b); printf(“The sum is = %d”, a+b); }
  • 34. Program 4 # include < stdio.h> #include <conio.h> void main() { int a,b; clrscr(); printf(“Please enter the value of a & b”); scanf(“%3d, %3d”, &a, &b); printf(“The sum is = %4d”, a+b); }