SlideShare a Scribd company logo
1 of 26
C-Programming Study Group
Honey Sharma
3rd year
BTech-open source software
What do you expect from this study group?
Things we will
focus upon:
1.Programming
2.Programming
3.Programming
C?
LANGUAGE? PROGRAMMING LANGUAGE?
C,C++,Java??
Procedural??
OBJECT ORIENTED??
COMPILED
Vs.
INTERPRETED??
Language Types
1.Machine languages
Strings of numbers giving
machine specific
instructions
Example:
+1300042774
2.Assembly Language
English-like abbreviations
representing elementary
computer operations
(translated via
assemblers)
Example:
Load BASEPAY
3.High-level languages
Codes similar to everyday
English
Example:
grossPay = basePay +
overTimePay
KNOW YOUR
TOOLS
GIT AND GITHUB?
Why do I need them?
Turbo c vs. GCC
Turbo C is a 16bit compiler. GCC is a 32 bit
compiler
Turbo C is obsolete -- on second thoughts,
fossil might a better adjective.
Does not support recent enough language
standards like C11 or C++11 or C++14
It is buggy, yes.
Turbo C is proprietary software; you cannot
see its source code (legally)
Turbo C produces poor executable code
GCC is a 32 bit compiler
GCC is supporting recent standards like C11 or
C++14.
GCC is free software, you can download legally,
study and improve its source code.
GCC is able to optimize
Use GCC with a good editor (e.g. emacs), and
a version control system (e.g. git) and a build
automation tool (e.g. GNU make)
The guy who designed Turbo C
moved on - so should you.
C89 vs. c99(c9x) vs. c11(c1x)
C89 or ANSI C( American National Standards
Institute)-1989
c99-underwent further revision in the late 1990s,
leading to the publication of ISO/IEC 9899:1999 in
1999
C11-current version of c programming language
released in 2011.
Introduction
Designed by Dennis
Ritchie at Bell
Laboratories in the
early 1970s
Influenced by
ALGOL 60 (1960),
CPL (Cambridge,
1963),
BCPL (Martin Richard,
1967),
B (Ken Thompson,
1970)
Traditionally used for
systems programming
So lets start coding……….
It's not at all important to get it right the first time. It's vitally important
to get it right the last time. ” - Andrew Hunt and David Thomas
Operators:
1.Arithmatic 2.Logical 3.Relational 4.Assignment
5.Increment
and
Decrement
Operators
Arithmetic Operators
+, - , *, / and the modulus operator %.
+ and – have the same precedence and associate left to right.
3 – 5 + 7 = ( 3 – 5 ) + 7  3 – ( 5 + 7 )
3 + 7 – 5 + 2 = ( ( 3 + 7 ) – 5 ) + 2
*, /, % have the same precedence and associate left to right.
The +, - group has lower precendence than the *, / % group.
3 – 5 * 7 / 8 + 6 / 2
3 – 35 / 8 + 6 / 2
3 – 4.375 + 6 / 2
3 – 4.375 + 3
-1.375 + 3
1.625
Operators
Arithmetic Operators
% is a modulus operator. x % y results in the remainder when x is
divided by y and is zero when x is divisible by y.
Cannot be applied to float or double variables.
Example
if ( num % 2 == 0 )
printf(“%d is an even numbern”, num);
else
printf(“%d is an odd numbern”, num);
Operators
Relational Operators
<, <=, > >=, ==, != are the relational operators. The expression
operand1 relational-operator operand2
takes a value of 1(int) if the relationship is true and 0(int) if relationship is
false.
Example
int a = 25, b = 30, c, d;
c = a < b;
d = a > b;
value of c will be 1 and that of d will be 0.
Operators
Logical Operators
&&, || and ! are the three logical operators.
expr1 && expr2 has a value 1 if expr1 and expr2 both are
nonzero.
expr1 || expr2 has a value 1 if expr1 and expr2 both are nonzero.
!expr1 has a value 1 if expr1 is zero else 0.
Example
if ( marks >= 40 && attendance >= 75 ) grade = ‘P’
If ( marks < 40 || attendance < 75 ) grade = ‘N’
21
Operators
Assignment operators
The general form of an assignment operator is
v op= exp
Where v is a variable and op is a binary arithmetic operator. This
statement is equivalent to
v = v op (exp)
a = a + b can be written as a += b
a = a * b can be written as a *= b
a = a / b can be written as a /= b
a = a - b can be written as a -= b
The operators ++ and –- are called increment and
decrement operators.
a++ and ++a are equivalent to a += 1.
a-- and --a are equivalent to a -= 1.
++a op b is equivalent to a ++; a op b;
a++ op b is equivalent to a op b; a++;
Example
Let b = 10 then
(++b)+b+b = 33
b+(++b)+b = 33
b+b+(++b) = 31
b+b*(++b) = 132
22
Operators
INCREMENT AND DECREMENT OPERATOR
The operators ++ and –- are called increment and decrement operators.
a++ and ++a are equivalent to a += 1.
a-- and --a are equivalent to a -= 1.
++a op b is equivalent to a ++; a op b;
a++ op b is equivalent to a op b; a++;
Example
Let b = 10 then
(++b)+b+b = 33
b+(++b)+b = 33
b+b+(++b) = 31
b+b*(++b) = 132
Logical Operators
 C defines these logical operators: <, >, <=,
>= and == (the equivalence operator)
 You can compare any variable. Characters
are compared based on their ASCII values.
 All answers will be true (not zero) or false
(0)
 You can extend the logic with && (and), !
(not) and || (or).
C Standard Header Files you may want to use
Standard Headers you should know about:
stdio.h – file and console (also a file) IO: perror, printf, open, close, read, write, scanf, etc.
stdlib.h - common utility functions: malloc, calloc, strtol, atoi, etc
string.h - string and byte manipulation: strlen, strcpy, strcat, memcpy, memset, etc.
ctype.h – character types: isalnum, isprint, isupport, tolower, etc.
errno.h – defines errno used for reporting system errors
math.h – math functions: ceil, exp, floor, sqrt, etc.
signal.h – signal handling facility: raise, signal, etc
stdint.h – standard integer: intN_t, uintN_t, etc
time.h – time related facility: asctime, clock, time_t, etc.
The Preprocessor
• The C preprocessor permits you to define simple macros that
are evaluated and expanded prior to compilation.
• Commands begin with a ‘#’. Abbreviated list:
– #define : defines a macro
– #undef : removes a macro definition
– #include : insert text from file
– #if : conditional based on value of expression
– #ifdef : conditional based on whether macro defined
– #ifndef : conditional based on whether macro is not defined
– #else : alternative
– #elif : conditional alternative
– defined() : preprocessor function: 1 if name defined, else 0
#if defined(__NetBSD__)
THANK YOU

More Related Content

What's hot (20)

Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
C++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer CentreC++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer Centre
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
 
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
C++ for beginners
C++ for beginnersC++ for beginners
C++ for beginners
 
Cbasic
CbasicCbasic
Cbasic
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
C++
C++C++
C++
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
 
C Programming basics
C Programming basicsC Programming basics
C Programming basics
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
C language basics
C language basicsC language basics
C language basics
 
c++
 c++  c++
c++
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICS
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c language
 

Similar to C Programming Introduction

Similar to C Programming Introduction (20)

B.sc CSIT 2nd semester C++ Unit2
B.sc CSIT  2nd semester C++ Unit2B.sc CSIT  2nd semester C++ Unit2
B.sc CSIT 2nd semester C++ Unit2
 
C program
C programC program
C program
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
 
2. operator
2. operator2. operator
2. operator
 
lecture1.ppt
lecture1.pptlecture1.ppt
lecture1.ppt
 
Programming in C by SONU KUMAR.pptx
Programming in C by SONU KUMAR.pptxProgramming in C by SONU KUMAR.pptx
Programming in C by SONU KUMAR.pptx
 
Overview of C Language
Overview of C LanguageOverview of C Language
Overview of C Language
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
C-PPT.pdf
C-PPT.pdfC-PPT.pdf
C-PPT.pdf
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Token and operators
Token and operatorsToken and operators
Token and operators
 
#Code2 create c++ for beginners
#Code2 create  c++ for beginners #Code2 create  c++ for beginners
#Code2 create c++ for beginners
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
C operators
C operatorsC operators
C operators
 
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
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
 
Cbasic
CbasicCbasic
Cbasic
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 

Recently uploaded

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 

Recently uploaded (20)

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 

C Programming Introduction

  • 1. C-Programming Study Group Honey Sharma 3rd year BTech-open source software
  • 2. What do you expect from this study group?
  • 3. Things we will focus upon: 1.Programming 2.Programming 3.Programming
  • 5. Language Types 1.Machine languages Strings of numbers giving machine specific instructions Example: +1300042774 2.Assembly Language English-like abbreviations representing elementary computer operations (translated via assemblers) Example: Load BASEPAY 3.High-level languages Codes similar to everyday English Example: grossPay = basePay + overTimePay
  • 7. GIT AND GITHUB? Why do I need them?
  • 8. Turbo c vs. GCC Turbo C is a 16bit compiler. GCC is a 32 bit compiler Turbo C is obsolete -- on second thoughts, fossil might a better adjective. Does not support recent enough language standards like C11 or C++11 or C++14 It is buggy, yes. Turbo C is proprietary software; you cannot see its source code (legally) Turbo C produces poor executable code GCC is a 32 bit compiler GCC is supporting recent standards like C11 or C++14. GCC is free software, you can download legally, study and improve its source code. GCC is able to optimize Use GCC with a good editor (e.g. emacs), and a version control system (e.g. git) and a build automation tool (e.g. GNU make)
  • 9. The guy who designed Turbo C moved on - so should you.
  • 10. C89 vs. c99(c9x) vs. c11(c1x) C89 or ANSI C( American National Standards Institute)-1989 c99-underwent further revision in the late 1990s, leading to the publication of ISO/IEC 9899:1999 in 1999 C11-current version of c programming language released in 2011.
  • 11. Introduction Designed by Dennis Ritchie at Bell Laboratories in the early 1970s Influenced by ALGOL 60 (1960), CPL (Cambridge, 1963), BCPL (Martin Richard, 1967), B (Ken Thompson, 1970) Traditionally used for systems programming
  • 12.
  • 13. So lets start coding……….
  • 14.
  • 15. It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas
  • 16. Operators: 1.Arithmatic 2.Logical 3.Relational 4.Assignment 5.Increment and Decrement
  • 17. Operators Arithmetic Operators +, - , *, / and the modulus operator %. + and – have the same precedence and associate left to right. 3 – 5 + 7 = ( 3 – 5 ) + 7  3 – ( 5 + 7 ) 3 + 7 – 5 + 2 = ( ( 3 + 7 ) – 5 ) + 2 *, /, % have the same precedence and associate left to right. The +, - group has lower precendence than the *, / % group. 3 – 5 * 7 / 8 + 6 / 2 3 – 35 / 8 + 6 / 2 3 – 4.375 + 6 / 2 3 – 4.375 + 3 -1.375 + 3 1.625
  • 18. Operators Arithmetic Operators % is a modulus operator. x % y results in the remainder when x is divided by y and is zero when x is divisible by y. Cannot be applied to float or double variables. Example if ( num % 2 == 0 ) printf(“%d is an even numbern”, num); else printf(“%d is an odd numbern”, num);
  • 19. Operators Relational Operators <, <=, > >=, ==, != are the relational operators. The expression operand1 relational-operator operand2 takes a value of 1(int) if the relationship is true and 0(int) if relationship is false. Example int a = 25, b = 30, c, d; c = a < b; d = a > b; value of c will be 1 and that of d will be 0.
  • 20. Operators Logical Operators &&, || and ! are the three logical operators. expr1 && expr2 has a value 1 if expr1 and expr2 both are nonzero. expr1 || expr2 has a value 1 if expr1 and expr2 both are nonzero. !expr1 has a value 1 if expr1 is zero else 0. Example if ( marks >= 40 && attendance >= 75 ) grade = ‘P’ If ( marks < 40 || attendance < 75 ) grade = ‘N’
  • 21. 21 Operators Assignment operators The general form of an assignment operator is v op= exp Where v is a variable and op is a binary arithmetic operator. This statement is equivalent to v = v op (exp) a = a + b can be written as a += b a = a * b can be written as a *= b a = a / b can be written as a /= b a = a - b can be written as a -= b
  • 22. The operators ++ and –- are called increment and decrement operators. a++ and ++a are equivalent to a += 1. a-- and --a are equivalent to a -= 1. ++a op b is equivalent to a ++; a op b; a++ op b is equivalent to a op b; a++; Example Let b = 10 then (++b)+b+b = 33 b+(++b)+b = 33 b+b+(++b) = 31 b+b*(++b) = 132 22 Operators INCREMENT AND DECREMENT OPERATOR The operators ++ and –- are called increment and decrement operators. a++ and ++a are equivalent to a += 1. a-- and --a are equivalent to a -= 1. ++a op b is equivalent to a ++; a op b; a++ op b is equivalent to a op b; a++; Example Let b = 10 then (++b)+b+b = 33 b+(++b)+b = 33 b+b+(++b) = 31 b+b*(++b) = 132
  • 23. Logical Operators  C defines these logical operators: <, >, <=, >= and == (the equivalence operator)  You can compare any variable. Characters are compared based on their ASCII values.  All answers will be true (not zero) or false (0)  You can extend the logic with && (and), ! (not) and || (or).
  • 24. C Standard Header Files you may want to use Standard Headers you should know about: stdio.h – file and console (also a file) IO: perror, printf, open, close, read, write, scanf, etc. stdlib.h - common utility functions: malloc, calloc, strtol, atoi, etc string.h - string and byte manipulation: strlen, strcpy, strcat, memcpy, memset, etc. ctype.h – character types: isalnum, isprint, isupport, tolower, etc. errno.h – defines errno used for reporting system errors math.h – math functions: ceil, exp, floor, sqrt, etc. signal.h – signal handling facility: raise, signal, etc stdint.h – standard integer: intN_t, uintN_t, etc time.h – time related facility: asctime, clock, time_t, etc.
  • 25. The Preprocessor • The C preprocessor permits you to define simple macros that are evaluated and expanded prior to compilation. • Commands begin with a ‘#’. Abbreviated list: – #define : defines a macro – #undef : removes a macro definition – #include : insert text from file – #if : conditional based on value of expression – #ifdef : conditional based on whether macro defined – #ifndef : conditional based on whether macro is not defined – #else : alternative – #elif : conditional alternative – defined() : preprocessor function: 1 if name defined, else 0 #if defined(__NetBSD__)