SlideShare une entreprise Scribd logo
1  sur  19
C PROGRAMMING
LECTURE
17th
August
IIT Kanpur
C Course, Programming club, Fall 2008
1
by
Deepak Majeti
M-Tech CSE
mdeepak@iitk.ac.in
Recap
C Course, Programming club, Fall 2008
2
 C is a high-level language.
 Writing a C code. {editors like gedit, vi}
 Compiling a C code. {gcc –c test.c –o test}
 Executing the object code. {./test}
Some more basics
C Course, Programming club, Fall 2008
3
 Keywords
 char, static, if , while, return ..................... Total= about 32
 Data Types
 int , char, float ...………..….. Some more later
 Arithmetic Operators
 + (Plus), - (Minus), * (Multiplication), /(Division)
……….………. Some more later
My first C program!
C Course, Programming club, Fall 2008
4
#include <stdio.h>
// program prints hello world
int main() {
printf ("Hello world!");
return 0;
}
Output: Hello world!
Example 1
C Course, Programming club, Fall
2008
5
#include <stdio.h>
// program prints a number of type int
int main() {
int number = 4;
printf (“Number is %d”, number);
return 0;
}
Output: Number is 4
Example 2
C Course, Programming club, Fall
2008
6
#include <stdio.h>
// program reads and prints the same thing
int main() {
int number ;
printf (“ Enter a Number: ”);
scanf (“%d”, &number);
printf (“Number is %dn”, number);
return 0;
}
Output : Enter a number: 4
Number is 4
more and more
C Course, Programming club, Fall 2008
7
#include <stdio.h>
int main() {
/* this program adds
two numbers */
int a = 4; //first number
int b = 5; //second number
int answer = 0; //result
answer = a + b;
}
Note
C Course, Programming club, Fall 2008
8
Errors
Compilation
Compiler generally gives the line number at
which the error is present.
Run time
C programs are sequential making the
debugging easier.
Some more Data Types
C Course, Programming club, Fall
2008
9
 Primary : int, float, char
 int (signed/unsigned)(2,4Bytes): used to store integers.
 char (signed/unsigned)(1Byte): used to store
characters
 float, double(4,8Bytes): used to store a decimal number.
 User Defined:
 typedef: used to rename a data type
 typedef int integer; can use integer to declare an int.
 enum, struct, union
Some more Arithmetic Operators
C Course, Programming club, Fall 2008
10
 Prefix Increment : ++a
 example:
 int a=5;
 b=++a; // value of b=6; a=6;
 Postfix Increment: a++
 example
 int a=5;
 b=a++; //value of b=5; a=6;
Contd…
C Course, Programming club, Fall 2008
11
 Modulus (remainder): %
 example:
 12%5 = 2;
 Assignment by addition: +=
 example:
 int a=4;
 a+=1; //(means a=a+1) value of a becomes 5
Can use -, /, *, % also
Contd…
C Course, Programming club, Fall 2008
12
 Comparision Operators: <, > , <=, >= , !=, ==, !,
&&, || .
 example:
 int a=4, b=5;
 a<b returns a true(non zero number) value.
 Bitwise Operators: <<, >>, ~, &, | ,^ .
 example
 int a=8;
 a= a>>1; // value of a becomes 4
Operator Precedence
C Course, Programming club, Fall 2008
13
 Meaning of a + b * c ?
is it a+(b*c) or (a+b)*c ?
 All operators have precedence over each other
 *, / have more precedence over +, - .
 If both *, / are used, associativity comes into
picture. (more on this later)
 example :
 5+4*3 = 5+12= 17.
Precedence Table
C Course, Programming club, Fall 2008
14
Highest on top
++ -- (Postfix)
++ -- (Prefix)
* / %
+ -
<< >>
< >
&
|
&&
||
Input / Output
C Course, Programming club, Fall 2008
15
 printf (); //used to print to console(screen)
 scanf (); //used to take an input from console(user).
 example: printf(“%c”, ’a’); scanf(“%d”, &a);
 More format specifiers
%c The character format specifier.
%d The integer format specifier.
%i The integer format specifier (same as %d).
%f The floating-point format specifier.
%o The unsigned octal format specifier.
%s The string format specifier.
%u The unsigned integer format specifier.
%x The unsigned hexadecimal format specifier.
%% Outputs a percent sign.
Some more geek stuff
C Course, Programming club, Fall 2008
16
 & in scanf.
 It is used to access the address of the variable used.
 example:
 scanf(%d,&a);
 we are reading into the address of a.
 Data Hierarchy.
 example:
 int value can be assigned to float not vice-versa.
 Type casting.
Home Work
C Course, Programming club, Fall 2008
17
 Meaning of
 Syntax
 Semantics of a programming language
 Find the Output:
 value=value++ + value++;
 Value=++value + ++value;
 value=value++ + ++value;
End of Today’s Lecture
C Course, Programming club, Fall 2008
18
Doubts && Queries?
THANK YOU
C Course, Programming club, Fall 2008
19

Contenu connexe

Tendances

C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++ Bharat Kalia
 
(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_iNico Ludwig
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#sudipv
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programminggajendra singh
 
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 eteachingeteaching
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageVincenzo De Florio
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training reportRaushan Pandey
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0xppd1961
 
Object Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioObject Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioDurgesh Singh
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 

Tendances (20)

Deep C
Deep CDeep C
Deep C
 
C vs c++
C vs c++C vs c++
C vs c++
 
C programming notes
C programming notesC programming notes
C programming notes
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i
 
Oop l2
Oop l2Oop l2
Oop l2
 
C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
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
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
Intro to C++ - language
Intro to C++ - languageIntro to C++ - language
Intro to C++ - language
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
 
Object Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World ScenarioObject Oriented Programming With Real-World Scenario
Object Oriented Programming With Real-World Scenario
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
C++ Interview Questions
C++ Interview QuestionsC++ Interview Questions
C++ Interview Questions
 

Similaire à 2. data, operators, io

2. data, operators, io
2. data, operators, io2. data, operators, io
2. data, operators, iohtaitk
 
2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt2. Data, Operators, IO.ppt
2. Data, Operators, IO.pptswateerawat06
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingAlpana Gupta
 
C prog ppt
C prog pptC prog ppt
C prog pptxinoe
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structuresPradipta Mishra
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures Pradipta Mishra
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptxRohitRaj744272
 
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docxrafbolet0
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manualAnil Bishnoi
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C BasicsBharat Kalia
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 FeaturesJan Rüegg
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 

Similaire à 2. data, operators, io (20)

2. data, operators, io
2. data, operators, io2. data, operators, io
2. data, operators, io
 
2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
 
Intro
IntroIntro
Intro
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
c.ppt
c.pptc.ppt
c.ppt
 
Cbasic
CbasicCbasic
Cbasic
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
C language
C languageC language
C language
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 

Dernier

Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodManicka Mamallan Andavar
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdfCaalaaAbdulkerim
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfComprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfalene1
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfBalamuruganV28
 
Turn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptxTurn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptxStephen Sitton
 
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.elesangwon
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHSneha Padhiar
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Erbil Polytechnic University
 
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfModule-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfManish Kumar
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosVictor Morales
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewsandhya757531
 
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptJohnWilliam111370
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptxmohitesoham12
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Communityprachaibot
 

Dernier (20)

Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument method
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdf
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfComprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
 
Designing pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptxDesigning pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptx
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdf
 
Turn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptxTurn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptx
 
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
 
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfModule-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitos
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overview
 
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptx
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Community
 

2. data, operators, io

  • 1. C PROGRAMMING LECTURE 17th August IIT Kanpur C Course, Programming club, Fall 2008 1 by Deepak Majeti M-Tech CSE mdeepak@iitk.ac.in
  • 2. Recap C Course, Programming club, Fall 2008 2  C is a high-level language.  Writing a C code. {editors like gedit, vi}  Compiling a C code. {gcc –c test.c –o test}  Executing the object code. {./test}
  • 3. Some more basics C Course, Programming club, Fall 2008 3  Keywords  char, static, if , while, return ..................... Total= about 32  Data Types  int , char, float ...………..….. Some more later  Arithmetic Operators  + (Plus), - (Minus), * (Multiplication), /(Division) ……….………. Some more later
  • 4. My first C program! C Course, Programming club, Fall 2008 4 #include <stdio.h> // program prints hello world int main() { printf ("Hello world!"); return 0; } Output: Hello world!
  • 5. Example 1 C Course, Programming club, Fall 2008 5 #include <stdio.h> // program prints a number of type int int main() { int number = 4; printf (“Number is %d”, number); return 0; } Output: Number is 4
  • 6. Example 2 C Course, Programming club, Fall 2008 6 #include <stdio.h> // program reads and prints the same thing int main() { int number ; printf (“ Enter a Number: ”); scanf (“%d”, &number); printf (“Number is %dn”, number); return 0; } Output : Enter a number: 4 Number is 4
  • 7. more and more C Course, Programming club, Fall 2008 7 #include <stdio.h> int main() { /* this program adds two numbers */ int a = 4; //first number int b = 5; //second number int answer = 0; //result answer = a + b; }
  • 8. Note C Course, Programming club, Fall 2008 8 Errors Compilation Compiler generally gives the line number at which the error is present. Run time C programs are sequential making the debugging easier.
  • 9. Some more Data Types C Course, Programming club, Fall 2008 9  Primary : int, float, char  int (signed/unsigned)(2,4Bytes): used to store integers.  char (signed/unsigned)(1Byte): used to store characters  float, double(4,8Bytes): used to store a decimal number.  User Defined:  typedef: used to rename a data type  typedef int integer; can use integer to declare an int.  enum, struct, union
  • 10. Some more Arithmetic Operators C Course, Programming club, Fall 2008 10  Prefix Increment : ++a  example:  int a=5;  b=++a; // value of b=6; a=6;  Postfix Increment: a++  example  int a=5;  b=a++; //value of b=5; a=6;
  • 11. Contd… C Course, Programming club, Fall 2008 11  Modulus (remainder): %  example:  12%5 = 2;  Assignment by addition: +=  example:  int a=4;  a+=1; //(means a=a+1) value of a becomes 5 Can use -, /, *, % also
  • 12. Contd… C Course, Programming club, Fall 2008 12  Comparision Operators: <, > , <=, >= , !=, ==, !, &&, || .  example:  int a=4, b=5;  a<b returns a true(non zero number) value.  Bitwise Operators: <<, >>, ~, &, | ,^ .  example  int a=8;  a= a>>1; // value of a becomes 4
  • 13. Operator Precedence C Course, Programming club, Fall 2008 13  Meaning of a + b * c ? is it a+(b*c) or (a+b)*c ?  All operators have precedence over each other  *, / have more precedence over +, - .  If both *, / are used, associativity comes into picture. (more on this later)  example :  5+4*3 = 5+12= 17.
  • 14. Precedence Table C Course, Programming club, Fall 2008 14 Highest on top ++ -- (Postfix) ++ -- (Prefix) * / % + - << >> < > & | && ||
  • 15. Input / Output C Course, Programming club, Fall 2008 15  printf (); //used to print to console(screen)  scanf (); //used to take an input from console(user).  example: printf(“%c”, ’a’); scanf(“%d”, &a);  More format specifiers %c The character format specifier. %d The integer format specifier. %i The integer format specifier (same as %d). %f The floating-point format specifier. %o The unsigned octal format specifier. %s The string format specifier. %u The unsigned integer format specifier. %x The unsigned hexadecimal format specifier. %% Outputs a percent sign.
  • 16. Some more geek stuff C Course, Programming club, Fall 2008 16  & in scanf.  It is used to access the address of the variable used.  example:  scanf(%d,&a);  we are reading into the address of a.  Data Hierarchy.  example:  int value can be assigned to float not vice-versa.  Type casting.
  • 17. Home Work C Course, Programming club, Fall 2008 17  Meaning of  Syntax  Semantics of a programming language  Find the Output:  value=value++ + value++;  Value=++value + ++value;  value=value++ + ++value;
  • 18. End of Today’s Lecture C Course, Programming club, Fall 2008 18 Doubts && Queries?
  • 19. THANK YOU C Course, Programming club, Fall 2008 19