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

ODP
Ppt of c vs c#
ODP
Ppt of c++ vs c#
PDF
C++ Training
PPTX
Presentation on C++ Programming Language
PPTX
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
PPT
OOP in C++
PPT
C and C++ Industrial Training Jalandhar
PPTX
Introduction Of C++
Ppt of c vs c#
Ppt of c++ vs c#
C++ Training
Presentation on C++ Programming Language
C and C ++ Training in Ambala ! BATRA COMPUTER CENTRE
OOP in C++
C and C++ Industrial Training Jalandhar
Introduction Of C++

What's hot (20)

PDF
Deep C
PPTX
C vs c++
PDF
C programming notes
PDF
C++ questions And Answer
PPT
Introduction to C++
ODP
(2) c sharp introduction_basics_part_i
PPTX
C++ vs C#
PPT
Introduction to c programming
PPS
basics of C and c++ by eteaching
PDF
Hands-on Introduction to the C Programming Language
DOCX
C language industrial training report
PDF
Intro to C++ - language
PPT
Glimpses of C++0x
PDF
Object Oriented Programming With Real-World Scenario
PPT
C++ Programming Course
PPTX
C Programming Language Tutorial for beginners - JavaTpoint
PPT
C++ Interview Questions
PDF
Object oriented programming c++
Deep C
C vs c++
C programming notes
C++ questions And Answer
Introduction to C++
(2) c sharp introduction_basics_part_i
C++ vs C#
Introduction to c programming
basics of C and c++ by eteaching
Hands-on Introduction to the C Programming Language
C language industrial training report
Intro to C++ - language
Glimpses of C++0x
Object Oriented Programming With Real-World Scenario
C++ Programming Course
C Programming Language Tutorial for beginners - JavaTpoint
C++ Interview Questions
Object oriented programming c++
Ad

Similar to 2. data, operators, io (20)

PPT
2. Data, Operators, IO (5).ppt
PPT
Data Types and Operators in C Programming
PPT
2. data, operators, io
PPT
2. Data, Operators, IO.ppt
PPT
M.Florence Dayana / Basics of C Language
PPTX
Fundamental programming Nota Topic 2.pptx
PPTX
the refernce of programming C notes ppt.pptx
PPT
c-programming
PPT
Cbasic
PPTX
Programming in C Basics
PPT
C tutorial
PDF
Fundamentals C programming and strong your skills.
PPTX
C introduction
PPT
Unit i intro-operators
PPTX
High performance computing seminar1.pptx
PPSX
C – A Programming Language- I
PPT
slidenotesece246jun2012-140803084954-phpapp01 (1).ppt
PPTX
C programming language
2. Data, Operators, IO (5).ppt
Data Types and Operators in C Programming
2. data, operators, io
2. Data, Operators, IO.ppt
M.Florence Dayana / Basics of C Language
Fundamental programming Nota Topic 2.pptx
the refernce of programming C notes ppt.pptx
c-programming
Cbasic
Programming in C Basics
C tutorial
Fundamentals C programming and strong your skills.
C introduction
Unit i intro-operators
High performance computing seminar1.pptx
C – A Programming Language- I
slidenotesece246jun2012-140803084954-phpapp01 (1).ppt
C programming language
Ad

Recently uploaded (20)

PDF
PPT on Performance Review to get promotions
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Structs to JSON How Go Powers REST APIs.pdf
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Well-logging-methods_new................
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Digital Logic Computer Design lecture notes
PDF
composite construction of structures.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Sustainable Sites - Green Building Construction
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Welding lecture in detail for understanding
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPT
Project quality management in manufacturing
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT on Performance Review to get promotions
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Structs to JSON How Go Powers REST APIs.pdf
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Well-logging-methods_new................
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Digital Logic Computer Design lecture notes
composite construction of structures.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Sustainable Sites - Green Building Construction
Mechanical Engineering MATERIALS Selection
Welding lecture in detail for understanding
bas. eng. economics group 4 presentation 1.pptx
Project quality management in manufacturing
Arduino robotics embedded978-1-4302-3184-4.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx

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