SlideShare a Scribd company logo
1 of 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

More Related Content

Similar to 2. Data, Operators, IO (5).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 structuresPradipta Mishra
 
Functions.pptx, programming language in c
Functions.pptx, programming language in cFunctions.pptx, programming language in c
Functions.pptx, programming language in cfloraaluoch3
 
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
 
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
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptxRohitRaj744272
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manualAnil Bishnoi
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
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
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 

Similar to 2. Data, Operators, IO (5).ppt (20)

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
 
Functions.pptx, programming language in c
Functions.pptx, programming language in cFunctions.pptx, programming language in c
Functions.pptx, programming language in c
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
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
 
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
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
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
 
C language
C languageC language
C language
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Cbasic
CbasicCbasic
Cbasic
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
AS TASKS #8
AS TASKS #8AS TASKS #8
AS TASKS #8
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 

More from Elisée Ndjabu

08_ digital electronics for engineers electronics.ppt
08_ digital electronics  for engineers electronics.ppt08_ digital electronics  for engineers electronics.ppt
08_ digital electronics for engineers electronics.pptElisée Ndjabu
 
11_Fundamentals_of_Digital_Electronics_L.pptx
11_Fundamentals_of_Digital_Electronics_L.pptx11_Fundamentals_of_Digital_Electronics_L.pptx
11_Fundamentals_of_Digital_Electronics_L.pptxElisée Ndjabu
 
07_arithmeticcircuits digital electronics.pptx
07_arithmeticcircuits digital electronics.pptx07_arithmeticcircuits digital electronics.pptx
07_arithmeticcircuits digital electronics.pptxElisée Ndjabu
 
296484860-Moving-Iron-Instruments for computer engineers.ppt
296484860-Moving-Iron-Instruments for computer engineers.ppt296484860-Moving-Iron-Instruments for computer engineers.ppt
296484860-Moving-Iron-Instruments for computer engineers.pptElisée Ndjabu
 
sp12Part2 CIRCUITS AND SYSTEMS FOR COMPUTER ENGINEERING .pptx
sp12Part2 CIRCUITS AND SYSTEMS FOR COMPUTER ENGINEERING .pptxsp12Part2 CIRCUITS AND SYSTEMS FOR COMPUTER ENGINEERING .pptx
sp12Part2 CIRCUITS AND SYSTEMS FOR COMPUTER ENGINEERING .pptxElisée Ndjabu
 
sp12Part4 CIRCUITS AND SYSTEMS FOR COMPUTER SCIENCE.pptx
sp12Part4 CIRCUITS AND SYSTEMS FOR COMPUTER SCIENCE.pptxsp12Part4 CIRCUITS AND SYSTEMS FOR COMPUTER SCIENCE.pptx
sp12Part4 CIRCUITS AND SYSTEMS FOR COMPUTER SCIENCE.pptxElisée Ndjabu
 
After COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptx
After COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptxAfter COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptx
After COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptxElisée Ndjabu
 
RESEARCH METHODOLOGY FOR COMPUTER ENGINEERS
RESEARCH METHODOLOGY FOR COMPUTER ENGINEERSRESEARCH METHODOLOGY FOR COMPUTER ENGINEERS
RESEARCH METHODOLOGY FOR COMPUTER ENGINEERSElisée Ndjabu
 
be5b99cpl-lec11-slides.pdf
be5b99cpl-lec11-slides.pdfbe5b99cpl-lec11-slides.pdf
be5b99cpl-lec11-slides.pdfElisée Ndjabu
 
be5b99cpl-lec01-slides.pdf
be5b99cpl-lec01-slides.pdfbe5b99cpl-lec01-slides.pdf
be5b99cpl-lec01-slides.pdfElisée Ndjabu
 
02_10-motherboards.pdf
02_10-motherboards.pdf02_10-motherboards.pdf
02_10-motherboards.pdfElisée Ndjabu
 
cupdf.com_ece-2300-circuit-analysis-dr-dave-shattuck-associate-professor-ece-...
cupdf.com_ece-2300-circuit-analysis-dr-dave-shattuck-associate-professor-ece-...cupdf.com_ece-2300-circuit-analysis-dr-dave-shattuck-associate-professor-ece-...
cupdf.com_ece-2300-circuit-analysis-dr-dave-shattuck-associate-professor-ece-...Elisée Ndjabu
 

More from Elisée Ndjabu (14)

08_ digital electronics for engineers electronics.ppt
08_ digital electronics  for engineers electronics.ppt08_ digital electronics  for engineers electronics.ppt
08_ digital electronics for engineers electronics.ppt
 
11_Fundamentals_of_Digital_Electronics_L.pptx
11_Fundamentals_of_Digital_Electronics_L.pptx11_Fundamentals_of_Digital_Electronics_L.pptx
11_Fundamentals_of_Digital_Electronics_L.pptx
 
07_arithmeticcircuits digital electronics.pptx
07_arithmeticcircuits digital electronics.pptx07_arithmeticcircuits digital electronics.pptx
07_arithmeticcircuits digital electronics.pptx
 
296484860-Moving-Iron-Instruments for computer engineers.ppt
296484860-Moving-Iron-Instruments for computer engineers.ppt296484860-Moving-Iron-Instruments for computer engineers.ppt
296484860-Moving-Iron-Instruments for computer engineers.ppt
 
sp12Part2 CIRCUITS AND SYSTEMS FOR COMPUTER ENGINEERING .pptx
sp12Part2 CIRCUITS AND SYSTEMS FOR COMPUTER ENGINEERING .pptxsp12Part2 CIRCUITS AND SYSTEMS FOR COMPUTER ENGINEERING .pptx
sp12Part2 CIRCUITS AND SYSTEMS FOR COMPUTER ENGINEERING .pptx
 
sp12Part4 CIRCUITS AND SYSTEMS FOR COMPUTER SCIENCE.pptx
sp12Part4 CIRCUITS AND SYSTEMS FOR COMPUTER SCIENCE.pptxsp12Part4 CIRCUITS AND SYSTEMS FOR COMPUTER SCIENCE.pptx
sp12Part4 CIRCUITS AND SYSTEMS FOR COMPUTER SCIENCE.pptx
 
After COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptx
After COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptxAfter COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptx
After COMPUTING THIS IS FOR COMPUTER SCIENTISTS.pptx
 
RESEARCH METHODOLOGY FOR COMPUTER ENGINEERS
RESEARCH METHODOLOGY FOR COMPUTER ENGINEERSRESEARCH METHODOLOGY FOR COMPUTER ENGINEERS
RESEARCH METHODOLOGY FOR COMPUTER ENGINEERS
 
2020920.pdf
2020920.pdf2020920.pdf
2020920.pdf
 
aads_print.pdf
aads_print.pdfaads_print.pdf
aads_print.pdf
 
be5b99cpl-lec11-slides.pdf
be5b99cpl-lec11-slides.pdfbe5b99cpl-lec11-slides.pdf
be5b99cpl-lec11-slides.pdf
 
be5b99cpl-lec01-slides.pdf
be5b99cpl-lec01-slides.pdfbe5b99cpl-lec01-slides.pdf
be5b99cpl-lec01-slides.pdf
 
02_10-motherboards.pdf
02_10-motherboards.pdf02_10-motherboards.pdf
02_10-motherboards.pdf
 
cupdf.com_ece-2300-circuit-analysis-dr-dave-shattuck-associate-professor-ece-...
cupdf.com_ece-2300-circuit-analysis-dr-dave-shattuck-associate-professor-ece-...cupdf.com_ece-2300-circuit-analysis-dr-dave-shattuck-associate-professor-ece-...
cupdf.com_ece-2300-circuit-analysis-dr-dave-shattuck-associate-professor-ece-...
 

Recently uploaded

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.pptxSCMS School of Architecture
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257subhasishdas79
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxhublikarsn
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsmeharikiros2
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxMustafa Ahmed
 
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.pptxSCMS School of Architecture
 
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 Kuwaitjaanualu31
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...ppkakm
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesRashidFaridChishti
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Ramkumar k
 
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 PlayEpec Engineered Technologies
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)ChandrakantDivate1
 

Recently uploaded (20)

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
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.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
 
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
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
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
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
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
 

2. Data, Operators, IO (5).ppt

  • 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