SlideShare a Scribd company logo
Introduction to ‘C’
P. Madhu Sudhana Rao
Embedded Software Developer
Presented by:
CLASS - 1
INDEX OF CONTENTS
• History of ‘C’
• Characteristics of ‘C’
• Structure of ‘C’
• Environment of ‘C’
• Elements of ‘C’
• How to Install Turbo C?
• How to Install GCC?
History of ‘C’
How it is evolved?
• Dennis Ritchie in 1970 at Bell Labs.
• UNIX Operating System.
Characteristics of ‘C’
Features of ‘C’
• Middle Level Language.
• Application Programs & System Programs.
• Small Language with 32 English words.
• Library Functions.
• Language is Extendible.
• Structured Program.
Structure of ‘C’
C PROGRAM
• Comment Section
• Preprocessor Section
• Global Declarations Section
• Main Section
• Local Declarations Section
• Logical Blocks
• Functions
• Local Declarations Section
• Logical Blocks
// C DEMO
#include<stdio.h>
#include<conio.h>
int a;
Void main()
{
char b;
------------------------------
-------------------------------
}
Func1()
{
int c;
----------------------------------
----------------------------------
}
COMMENTS SECTION
• Comments are programmer friendly.
• Compiler will never execute comments.
• Two types of Comments
– Single Line Comment
• Syntax: // ……………….
– Multiple Line Comment
• Syntax: /* ………………………….
………………………….*/
PREPROCESSOR SECTION
• C PRE PROCESSOR
• Directives
• #include, #define etc…
• How to define constant value
– Syntax: #define mad 2.2
• How to include library file
– Syntax: #include <HedarFile.h>
DECLARATION SECTION
• Scope
• Two Sections
– Global Declaration
• Syntax: Data_Type Variable_name;
– Local Declaration
• Syntax: Data_Type Variable_name;
Later ….
Functions, Logical Blocks can be discussed later
and nothing to worry at this point of time.
Environment of ‘C’
COMPILATION PROCESS
SOURCE CODE
PRE PROCESSOR
COMPILER
ASSEMBLER
LINKER
EXECUTABLE CODE
EXPANDED CODE
ASSEMBLY CODE
OBJECT CODE
OTHER OBJECT FILES
LIBRARIES
Two Compilers
• Download Turbo C from Google Drive.
• Download Code Blocks from Google Drive.
Follow the PRESENTATION…
In the practical session, download and install them
ELEMENTS OF ‘C’
BASIC ELEMENTS
• Character Set
• Keywords
• Identifiers
• Data Types
• Constants
• Variables
• Expressions
• Statements
• Comments
CHARACTER SET
• Alphabets [a-z, A-Z]
• Digits [0 – 9]
• Escape Sequences
ESCAPE SEQUENCE MEANING
b BACKSPACE
a ALERT
r CARRIAGE RETURN
n NEWLINE
0 NULL
t HORIZONTAL TAB
 BACKSLASH
KEYWORDS
• Lowercase
• 32 Keywords in ‘C’
auto; break; case; char; const; continue;
default;do;double;else;enum;extern;float;for;
goto;if;int;long;register;return;short;signed;
sizeof;static;struct;switch;typedef;union;
unsigned;void;volatile;while
IDENTIFIERS
• Words  Keywords or Identifiers
• Rules:
– The name should consist of alphabets, digits and underscore sign.
– First character should be an alphabet or underscore.
– The name should not be a keyword.
– Since C is case sensitive, the upper case and lower case are different.
– An identifier name may be arbitrarily long.
• Only 8 preferable and upto 31.
5bc int rec# avg no
DATA TYPES
• Memory Allocation
• Four Fundamental
– int, char, float, double
• Size Qualifiers
– short, long
• Sign Qualifiers
– signed, unsigned
BASIC DATA
TYPE
DATA TYPE SIZE RANGE
char char or signed char 1 -128 to 127
unsigned char 1 0 to 255
Int int or signed int 4 -2147483648 to +2147483647
unsigned int 4 0 to 4294967295
Short int or signed short
int
2 -32768 to +32767
Unsigned short int 2 0 to 65535
Long int or signed long int 4 -2147483648 to +2147483647
Unsigned long int 4 0 to 4294967295
float float 4 3.4E-38 to 3.4E+38
double double 8 1.7E-308 to 1.7E+308
long double 10 3.4D-4932 to 1.1E+4932
32-BIT MACHINE DATA TYPES
CONSTANTS
• Can’t be changed throughout the execution
• 3 Types of Constants
– Numeric Constants
• Integer Constants
• Real Constants
– Character Constants
– String Constants
VARIABLES
• Store a value
• Declaration of Variables
– Syntax: int x;
• Initialization of Variables
– Syntax: int x=5;
EXPRESSIONS
• Arithmetic Expressions
– Syntax: x+y;
• Relational Expressions
– Syntax: a>b;
• Logical Expressions
– Syntax: a==b;
• Function Calls
– Syntax: func(a,b);
STATEMENTS
• Expression Statements [x=5, x=y-z]
• Compound Statements [x*y*z+y*z+z*x]
• Selection Statements [if, if…else,switch]
• Iterative Statements [for, while, do…while]
• Jump Statements [goto, continue, break, ret]
• Label Statements [case, default, goto label]
COMMENTS
• Increases the readability of a program.
• Write anywhere in the program.
• Comments can’t be nested.
• Can’t be written inside string constant or a
character constant.
QUERIES
CONTACT
P. Madhu Sudhana Rao
Embedded Software Developer
Orange Research Labs
@: msr@orangeresearchlabs.com
WWW: madresearch.wordpress.com
I/O, OPERATORS in ‘C’
P. Madhu Sudhana Rao
Embedded Software Developer
Presented by:
CLASS - 2
INDEX OF CONTENTS
• Conversion Specifications
• Reading Input Data
• Writing Output Data
• getchar() and putchar()
• Operators
• Types
• Precedence and Associativity of Operators
CONVERSION SPECIFICATIONS
%
• %C Single Character
• %d Decimal Integer
• %f  Floating Point Number
• %o  Octal Integer
• %x  Hexa Decimal Integer
• %s  String
• %u  Unsigned Decimal Integer
READING INPUT DATA
SCANF ()
• Used to read the data.
• Minimum no of Arguments: 2
• Returns the no of variables read.
Syntax:
scanf(“control string”, add1, add2…);
WRITING OUTPUT DATA
PRINTF ()
• Used to write the data.
• Minimum no of arguments: 1
• Returns the no of characters printed.
Syntax:
printf(“control string”, variable1, variable2…);
Getchar () and Putchar()
• To read a character, then get
Syntax: ch=getchar();
• To write a character, then put
Syntax: putchar(ch);
OPERATORS
Types of Operators
• Arithmetic Operators
• Assignment Operators
• Increment and Decrement Operators
• Relational Operators
• Logical Operators
• Conditional Operators
• Comma Operators
• sizeof Operators
• Bitwise Operators
Arithmetical Operators
• Unary Arithmetic Operators
• Binary Arithmetic Operators
Examples [Unary]: +x, -y
Examples [Binary]: +, -, *, /, %
Assignment Operators
• Storing of a value.
• Left Hand Side: Variable.
• Right Hand Side: Value.
Examples:
X=8, s=x+y-2, y=x
X+=5 [+= Compound Assignment Operator]
Increment and Decrement
Operators
• Increment (++)
• Decrement (--)
• Prefix
• Postfix
Relational Operators
• Comparison
• <, <=, >, >=, ==, !=
Logical or Boolean Operators
• AND (&&), OR (||), NOT (!)
Conditional Operators
• ?:
• TestExpression?Expression1:Expression2
• True  Expression1
• False  Expression2
Comma Operator
• Comma separates the expressions.
sizeof Operator
• Sizeof is an unary operator.
Syntax: sizeof(variable);
Bitwise Operators
• Bitwise AND (&),
• Bitwise OR (|),
• One’s Complement (~),
• Bitwise Left Shift (<<),
• Bitwise Right Shift (>>),
• Bitwise XOR (^)
Associativity of Operators
Operators Associativity
::a a::b left to right
a() a[b] a->b a[b..c] ({}) ([]) (<>) left to right
a++ a-- left to right
!a ~a (type)a ++a --a right to left!
a*b a/b a%b left to right
a+b a-b left to right
a>>b a<<b left to right
a>b a>=b a<b a<=b left to right
a==b a!=b left to right
a&b left to right
a^b left to right
a|b left to right
&& left to right
|| left to right
a?b:c right to left
= += -= *= /= %= <<= >>= &= |= ^=
right to left
@a right to left
, left to right
Examples
This expression is evaluated in this order
1+2*2 1+(2*2)
1+2*2*4 1+((2*2)*4)
(1+2)*2*4 ((1+2)*2)*4
1+4,c=2|3+5 (1+4),(c=(2|(3+5)))
1 + 5&4 == 3 (1 + 5) & (4 == 3)
c=1,99 (c=1),99
!a++ + ~f() (!(a++)) + (~(f()))
s == “mad" || i < 9 (s == “mad") || (i < 9)
r = s == “mad" r = (s == “mad")
QUERIES
CONTACT
P. Madhu Sudhana Rao
Embedded Software Developer
Orange Research Labs
@: msr@orangeresearchlabs.com
WWW: madresearch.wordpress.com

More Related Content

What's hot

Programming C Language
Programming C LanguageProgramming C Language
Programming C Language
natarafonseca
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICS
Aami Kakakhel
 
Perl Intro 3 Datalog Parsing
Perl Intro 3 Datalog ParsingPerl Intro 3 Datalog Parsing
Perl Intro 3 Datalog Parsing
Shaun Griffith
 

What's hot (19)

C programming tutorial for Beginner
C programming tutorial for BeginnerC programming tutorial for Beginner
C programming tutorial for Beginner
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
 
Programming C Language
Programming C LanguageProgramming C Language
Programming C Language
 
C language basics
C language basicsC language basics
C language basics
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Session 06 - Java Basics
Session 06 - Java BasicsSession 06 - Java Basics
Session 06 - Java Basics
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICS
 
C language programming
C language programmingC language programming
C language programming
 
C Programming basics
C Programming basicsC Programming basics
C Programming basics
 
C - - Grammar 1.0
C - - Grammar 1.0C - - Grammar 1.0
C - - Grammar 1.0
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
Perl Intro 3 Datalog Parsing
Perl Intro 3 Datalog ParsingPerl Intro 3 Datalog Parsing
Perl Intro 3 Datalog Parsing
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c language
 

Similar to c

Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptx
Ronaldo Aditya
 

Similar to c (20)

Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
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
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
 
C PROGRAMING.pptx
C PROGRAMING.pptxC PROGRAMING.pptx
C PROGRAMING.pptx
 
C
CC
C
 
Lec-1c.pdf
Lec-1c.pdfLec-1c.pdf
Lec-1c.pdf
 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptx
 
07 control+structures
07 control+structures07 control+structures
07 control+structures
 
C language
C languageC language
C language
 
Basics of c
Basics of cBasics of c
Basics of c
 
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.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
 

Recently uploaded

皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
larisashrestha558
 
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Dirk Spencer Corporate Recruiter LION
 
Dr. Nazrul Islam, Northern University Bangladesh - CV (29.5.2024).pdf
Dr. Nazrul Islam, Northern University Bangladesh - CV (29.5.2024).pdfDr. Nazrul Islam, Northern University Bangladesh - CV (29.5.2024).pdf
Dr. Nazrul Islam, Northern University Bangladesh - CV (29.5.2024).pdf
Dr. Nazrul Islam
 

Recently uploaded (20)

0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf
0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf
0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf
 
Day care leadership document it helps to a person who needs caring children
Day care leadership document it helps to a person who needs caring childrenDay care leadership document it helps to a person who needs caring children
Day care leadership document it helps to a person who needs caring children
 
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
 
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
 
D.El.Ed. College List -Session 2024-26.pdf
D.El.Ed. College List -Session 2024-26.pdfD.El.Ed. College List -Session 2024-26.pdf
D.El.Ed. College List -Session 2024-26.pdf
 
129. Reviewer Certificate in BioNature [2024]
129. Reviewer Certificate in BioNature [2024]129. Reviewer Certificate in BioNature [2024]
129. Reviewer Certificate in BioNature [2024]
 
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
 
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid feverWidal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
 
133. Reviewer Certificate in Advances in Research
133. Reviewer Certificate in Advances in Research133. Reviewer Certificate in Advances in Research
133. Reviewer Certificate in Advances in Research
 
132. Acta Scientific Pharmaceutical Sciences
132. Acta Scientific Pharmaceutical Sciences132. Acta Scientific Pharmaceutical Sciences
132. Acta Scientific Pharmaceutical Sciences
 
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
 
Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!
 
0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf
0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf
0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf
 
Biography and career history of Chad Henson.pdf
Biography and career history of Chad Henson.pdfBiography and career history of Chad Henson.pdf
Biography and career history of Chad Henson.pdf
 
0524.priorspeakingengagementslist-01.pdf
0524.priorspeakingengagementslist-01.pdf0524.priorspeakingengagementslist-01.pdf
0524.priorspeakingengagementslist-01.pdf
 
欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】
欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】
欧洲杯投注网站-欧洲杯投注网站推荐-欧洲杯投注网站| 立即访问【ac123.net】
 
Dr. Nazrul Islam, Northern University Bangladesh - CV (29.5.2024).pdf
Dr. Nazrul Islam, Northern University Bangladesh - CV (29.5.2024).pdfDr. Nazrul Islam, Northern University Bangladesh - CV (29.5.2024).pdf
Dr. Nazrul Islam, Northern University Bangladesh - CV (29.5.2024).pdf
 
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
 
Chapters 3 Contracts.pptx Chapters 3 Contracts.pptx
Chapters 3  Contracts.pptx Chapters 3  Contracts.pptxChapters 3  Contracts.pptx Chapters 3  Contracts.pptx
Chapters 3 Contracts.pptx Chapters 3 Contracts.pptx
 
How to Master LinkedIn for Career and Business
How to Master LinkedIn for Career and BusinessHow to Master LinkedIn for Career and Business
How to Master LinkedIn for Career and Business
 

c

  • 1. Introduction to ‘C’ P. Madhu Sudhana Rao Embedded Software Developer Presented by: CLASS - 1
  • 2. INDEX OF CONTENTS • History of ‘C’ • Characteristics of ‘C’ • Structure of ‘C’ • Environment of ‘C’ • Elements of ‘C’ • How to Install Turbo C? • How to Install GCC?
  • 4. How it is evolved? • Dennis Ritchie in 1970 at Bell Labs. • UNIX Operating System.
  • 6. Features of ‘C’ • Middle Level Language. • Application Programs & System Programs. • Small Language with 32 English words. • Library Functions. • Language is Extendible. • Structured Program.
  • 8. C PROGRAM • Comment Section • Preprocessor Section • Global Declarations Section • Main Section • Local Declarations Section • Logical Blocks • Functions • Local Declarations Section • Logical Blocks // C DEMO #include<stdio.h> #include<conio.h> int a; Void main() { char b; ------------------------------ ------------------------------- } Func1() { int c; ---------------------------------- ---------------------------------- }
  • 9. COMMENTS SECTION • Comments are programmer friendly. • Compiler will never execute comments. • Two types of Comments – Single Line Comment • Syntax: // ………………. – Multiple Line Comment • Syntax: /* …………………………. ………………………….*/
  • 10. PREPROCESSOR SECTION • C PRE PROCESSOR • Directives • #include, #define etc… • How to define constant value – Syntax: #define mad 2.2 • How to include library file – Syntax: #include <HedarFile.h>
  • 11. DECLARATION SECTION • Scope • Two Sections – Global Declaration • Syntax: Data_Type Variable_name; – Local Declaration • Syntax: Data_Type Variable_name;
  • 12. Later …. Functions, Logical Blocks can be discussed later and nothing to worry at this point of time.
  • 14. COMPILATION PROCESS SOURCE CODE PRE PROCESSOR COMPILER ASSEMBLER LINKER EXECUTABLE CODE EXPANDED CODE ASSEMBLY CODE OBJECT CODE OTHER OBJECT FILES LIBRARIES
  • 15. Two Compilers • Download Turbo C from Google Drive. • Download Code Blocks from Google Drive. Follow the PRESENTATION… In the practical session, download and install them
  • 17. BASIC ELEMENTS • Character Set • Keywords • Identifiers • Data Types • Constants • Variables • Expressions • Statements • Comments
  • 18. CHARACTER SET • Alphabets [a-z, A-Z] • Digits [0 – 9] • Escape Sequences ESCAPE SEQUENCE MEANING b BACKSPACE a ALERT r CARRIAGE RETURN n NEWLINE 0 NULL t HORIZONTAL TAB BACKSLASH
  • 19. KEYWORDS • Lowercase • 32 Keywords in ‘C’ auto; break; case; char; const; continue; default;do;double;else;enum;extern;float;for; goto;if;int;long;register;return;short;signed; sizeof;static;struct;switch;typedef;union; unsigned;void;volatile;while
  • 20. IDENTIFIERS • Words  Keywords or Identifiers • Rules: – The name should consist of alphabets, digits and underscore sign. – First character should be an alphabet or underscore. – The name should not be a keyword. – Since C is case sensitive, the upper case and lower case are different. – An identifier name may be arbitrarily long. • Only 8 preferable and upto 31. 5bc int rec# avg no
  • 21. DATA TYPES • Memory Allocation • Four Fundamental – int, char, float, double • Size Qualifiers – short, long • Sign Qualifiers – signed, unsigned
  • 22. BASIC DATA TYPE DATA TYPE SIZE RANGE char char or signed char 1 -128 to 127 unsigned char 1 0 to 255 Int int or signed int 4 -2147483648 to +2147483647 unsigned int 4 0 to 4294967295 Short int or signed short int 2 -32768 to +32767 Unsigned short int 2 0 to 65535 Long int or signed long int 4 -2147483648 to +2147483647 Unsigned long int 4 0 to 4294967295 float float 4 3.4E-38 to 3.4E+38 double double 8 1.7E-308 to 1.7E+308 long double 10 3.4D-4932 to 1.1E+4932 32-BIT MACHINE DATA TYPES
  • 23. CONSTANTS • Can’t be changed throughout the execution • 3 Types of Constants – Numeric Constants • Integer Constants • Real Constants – Character Constants – String Constants
  • 24. VARIABLES • Store a value • Declaration of Variables – Syntax: int x; • Initialization of Variables – Syntax: int x=5;
  • 25. EXPRESSIONS • Arithmetic Expressions – Syntax: x+y; • Relational Expressions – Syntax: a>b; • Logical Expressions – Syntax: a==b; • Function Calls – Syntax: func(a,b);
  • 26. STATEMENTS • Expression Statements [x=5, x=y-z] • Compound Statements [x*y*z+y*z+z*x] • Selection Statements [if, if…else,switch] • Iterative Statements [for, while, do…while] • Jump Statements [goto, continue, break, ret] • Label Statements [case, default, goto label]
  • 27. COMMENTS • Increases the readability of a program. • Write anywhere in the program. • Comments can’t be nested. • Can’t be written inside string constant or a character constant.
  • 29.
  • 30. CONTACT P. Madhu Sudhana Rao Embedded Software Developer Orange Research Labs @: msr@orangeresearchlabs.com WWW: madresearch.wordpress.com
  • 31. I/O, OPERATORS in ‘C’ P. Madhu Sudhana Rao Embedded Software Developer Presented by: CLASS - 2
  • 32. INDEX OF CONTENTS • Conversion Specifications • Reading Input Data • Writing Output Data • getchar() and putchar() • Operators • Types • Precedence and Associativity of Operators
  • 34. % • %C Single Character • %d Decimal Integer • %f  Floating Point Number • %o  Octal Integer • %x  Hexa Decimal Integer • %s  String • %u  Unsigned Decimal Integer
  • 36. SCANF () • Used to read the data. • Minimum no of Arguments: 2 • Returns the no of variables read. Syntax: scanf(“control string”, add1, add2…);
  • 38. PRINTF () • Used to write the data. • Minimum no of arguments: 1 • Returns the no of characters printed. Syntax: printf(“control string”, variable1, variable2…);
  • 39. Getchar () and Putchar() • To read a character, then get Syntax: ch=getchar(); • To write a character, then put Syntax: putchar(ch);
  • 41. Types of Operators • Arithmetic Operators • Assignment Operators • Increment and Decrement Operators • Relational Operators • Logical Operators • Conditional Operators • Comma Operators • sizeof Operators • Bitwise Operators
  • 42. Arithmetical Operators • Unary Arithmetic Operators • Binary Arithmetic Operators Examples [Unary]: +x, -y Examples [Binary]: +, -, *, /, %
  • 43. Assignment Operators • Storing of a value. • Left Hand Side: Variable. • Right Hand Side: Value. Examples: X=8, s=x+y-2, y=x X+=5 [+= Compound Assignment Operator]
  • 44. Increment and Decrement Operators • Increment (++) • Decrement (--) • Prefix • Postfix
  • 46. Logical or Boolean Operators • AND (&&), OR (||), NOT (!)
  • 47. Conditional Operators • ?: • TestExpression?Expression1:Expression2 • True  Expression1 • False  Expression2
  • 48. Comma Operator • Comma separates the expressions.
  • 49. sizeof Operator • Sizeof is an unary operator. Syntax: sizeof(variable);
  • 50. Bitwise Operators • Bitwise AND (&), • Bitwise OR (|), • One’s Complement (~), • Bitwise Left Shift (<<), • Bitwise Right Shift (>>), • Bitwise XOR (^)
  • 52. Operators Associativity ::a a::b left to right a() a[b] a->b a[b..c] ({}) ([]) (<>) left to right a++ a-- left to right !a ~a (type)a ++a --a right to left! a*b a/b a%b left to right a+b a-b left to right a>>b a<<b left to right a>b a>=b a<b a<=b left to right a==b a!=b left to right a&b left to right a^b left to right a|b left to right && left to right || left to right a?b:c right to left = += -= *= /= %= <<= >>= &= |= ^= right to left @a right to left , left to right
  • 53. Examples This expression is evaluated in this order 1+2*2 1+(2*2) 1+2*2*4 1+((2*2)*4) (1+2)*2*4 ((1+2)*2)*4 1+4,c=2|3+5 (1+4),(c=(2|(3+5))) 1 + 5&4 == 3 (1 + 5) & (4 == 3) c=1,99 (c=1),99 !a++ + ~f() (!(a++)) + (~(f())) s == “mad" || i < 9 (s == “mad") || (i < 9) r = s == “mad" r = (s == “mad")
  • 55.
  • 56. CONTACT P. Madhu Sudhana Rao Embedded Software Developer Orange Research Labs @: msr@orangeresearchlabs.com WWW: madresearch.wordpress.com