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

PPT
2. data, operators, io
PPT
2. Data, Operators, IO in C Programing and its features
PPT
Data Types and Operators in C Programming
PPT
2. data, operators, io
PPT
2. Data, Operators, IO.ppt
PPTX
the refernce of programming C notes ppt.pptx
PPTX
Fundamental programming Nota Topic 2.pptx
PPT
Cbasic
2. data, operators, io
2. Data, Operators, IO in C Programing and its features
Data Types and Operators in C Programming
2. data, operators, io
2. Data, Operators, IO.ppt
the refernce of programming C notes ppt.pptx
Fundamental programming Nota Topic 2.pptx
Cbasic

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

PPT
C tutorial
PPTX
Programming in C Basics
PPT
c-programming
PPT
M.Florence Dayana / Basics of C Language
PDF
Fundamentals C programming and strong your skills.
PDF
Lec08-CS110 Computational Engineering
PPT
Unit i intro-operators
PPSX
C – A Programming Language- I
PPTX
C introduction
PPT
slidenotesece246jun2012-140803084954-phpapp01 (1).ppt
PPTX
High performance computing seminar1.pptx
PPTX
C programming language
PPT
270_1_ChapterIntro_Up_To_Functions (1).ppt
PPTX
Lecture 01 Programming C for Beginners 001
PPT
CIntro_Up_To_Functions.ppt;uoooooooooooooooooooo
PPT
270_1_CIntro_Up_To_Functions.ppt 0478 computer
PPT
270_1_CIntro_Up_To_Functions.ppt
C tutorial
Programming in C Basics
c-programming
M.Florence Dayana / Basics of C Language
Fundamentals C programming and strong your skills.
Lec08-CS110 Computational Engineering
Unit i intro-operators
C – A Programming Language- I
C introduction
slidenotesece246jun2012-140803084954-phpapp01 (1).ppt
High performance computing seminar1.pptx
C programming language
270_1_ChapterIntro_Up_To_Functions (1).ppt
Lecture 01 Programming C for Beginners 001
CIntro_Up_To_Functions.ppt;uoooooooooooooooooooo
270_1_CIntro_Up_To_Functions.ppt 0478 computer
270_1_CIntro_Up_To_Functions.ppt

More from Elisée Ndjabu (20)

PPTX
Chapter_04_ARM_Assembly ARM assembly language is the low-level programming.pptx
PPTX
Chapter_05_x86_assembly ARM processors have a number of general-purpose regis...
PPTX
Chapter_06_riscv.pptx Chapter_11_memory_system this is part of computer archi...
PPTX
Chapter_11_memory_system this is part of computer architecture.pptx
PPT
this is lecture two of the course that teaches about embedded systems
PPT
this is lecture one of the course that teaches about embedded systems
PPTX
Chapter_13_Input_Output_and_Storage_Devices.pptx
PPTX
chapter 6 here is about risc processors and ciscs
PPT
LES COURS DE RESEAUX INFORMATIQUE POUR LE DEBUTANTS
PPTX
Troubleshooting and software HADWARE.pptx
PPTX
this is the display for laptop computer sLCD.pptx
PPT
computer maintenance and repairMotherboard.ppt
PPT
253000215- ELECTRONI2QUE DE PUISSANCE Redresseur-C-ppt.ppt
PPT
COMPUTER FAULTS AND SOLUTIONS IN MAINTENANCE .ppt
PPT
Module_5-Processors and sockets.18213704.ppt
PPTX
381402142-Disassembling-System-Unit-Procedure-and-Safety-Precautions.pptx
PDF
les diodes electronique de puisssnce 4_diodes.pdf
PDF
pdfcoffee.com_polycopie-de-cours-ppt-lge604-20012-bf-pdf-free.pdf
PPT
couplage d'alternateurs couplage_alternateurs.ppt
PDF
electronique de puissance Electronique-de-puissance-cours-N°5.pdf
Chapter_04_ARM_Assembly ARM assembly language is the low-level programming.pptx
Chapter_05_x86_assembly ARM processors have a number of general-purpose regis...
Chapter_06_riscv.pptx Chapter_11_memory_system this is part of computer archi...
Chapter_11_memory_system this is part of computer architecture.pptx
this is lecture two of the course that teaches about embedded systems
this is lecture one of the course that teaches about embedded systems
Chapter_13_Input_Output_and_Storage_Devices.pptx
chapter 6 here is about risc processors and ciscs
LES COURS DE RESEAUX INFORMATIQUE POUR LE DEBUTANTS
Troubleshooting and software HADWARE.pptx
this is the display for laptop computer sLCD.pptx
computer maintenance and repairMotherboard.ppt
253000215- ELECTRONI2QUE DE PUISSANCE Redresseur-C-ppt.ppt
COMPUTER FAULTS AND SOLUTIONS IN MAINTENANCE .ppt
Module_5-Processors and sockets.18213704.ppt
381402142-Disassembling-System-Unit-Procedure-and-Safety-Precautions.pptx
les diodes electronique de puisssnce 4_diodes.pdf
pdfcoffee.com_polycopie-de-cours-ppt-lge604-20012-bf-pdf-free.pdf
couplage d'alternateurs couplage_alternateurs.ppt
electronique de puissance Electronique-de-puissance-cours-N°5.pdf

Recently uploaded (20)

PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
composite construction of structures.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Digital Logic Computer Design lecture notes
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Artificial Intelligence
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPT
Project quality management in manufacturing
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Foundation to blockchain - A guide to Blockchain Tech
Automation-in-Manufacturing-Chapter-Introduction.pdf
composite construction of structures.pdf
bas. eng. economics group 4 presentation 1.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Digital Logic Computer Design lecture notes
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
additive manufacturing of ss316l using mig welding
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
UNIT-1 - COAL BASED THERMAL POWER PLANTS
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
OOP with Java - Java Introduction (Basics)
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Artificial Intelligence
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Project quality management in manufacturing

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