SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Semelhante a 2. data, operators, io

2. data, operators, io
2. data, operators, io2. data, operators, io
2. data, operators, io
htaitk
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Alpana Gupta
 
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
rafbolet0
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
Hattori Sidek
 

Semelhante a 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
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Cbasic
CbasicCbasic
Cbasic
 
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
 

Último

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Último (20)

Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 

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