SlideShare a Scribd company logo
1




C PROGRAMMING
    LECTURE

                     by
                Deepak Majeti
                 M-Tech CSE
               mdeepak@iitk.ac.in

 17th August
                          C Course, Programming club, Fall 2008
 IIT Kanpur
Recap
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}


                                        C Course, Programming club, Fall 2008
Some more basics
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


                           C Course, Programming club, Fall 2008
My first C program!
4


    #include <stdio.h>
    // program prints hello world
    int main() {
      printf ("Hello world!");
      return 0;
    }

    Output: Hello world!

                                    C Course, Programming club, Fall 2008
Example 1
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

                                   C Course, Programming club, Fall
                                                             2008
Example 2
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
                                        C Course, Programming club, Fall
                                                                  2008
more and more
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;
    }

                                   C Course, Programming club, Fall 2008
Note
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.


                 C Course, Programming club, Fall 2008
Some more Data Types
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
                                                  C Course, Programming club, Fall
                                                                            2008
Some more Arithmetic Operators
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;


                           C Course, Programming club, Fall 2008
Contd…
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

                          C Course, Programming club, Fall 2008
Contd…
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


                           C Course, Programming club, Fall 2008
Operator Precedence
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.



                           C Course, Programming club, Fall 2008
Precedence Table
14

                       Highest on top
                       ++       -- (Postfix)
                       ++       -- (Prefix)
                       *         /         %
                            +          -
                           <<         >>
                           <          >
                                &
                                 |
                                &&
                                 ||

              C Course, Programming club, Fall 2008
Input / Output
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.
                           C Course, Programming club, Fall 2008
Some more geek stuff
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.


                            C Course, Programming club, Fall 2008
Home Work
17


        Meaning of
            Syntax
            Semantics of a programming language
        Find the Output:
            value=value++ + value++;
            Value=++value + ++value;
            value=value++ + ++value;



                       C Course, Programming club, Fall 2008
End of Today’s Lecture
18




          Doubts && Queries?



              C Course, Programming club, Fall 2008
19




     THANK                      YOU



     C Course, Programming club, Fall 2008

More Related Content

PPTX
C language
PDF
Reduce course notes class xii
PDF
Hands-on Introduction to the C Programming Language
PPT
C and C++ Industrial Training Jalandhar
PPTX
Introduction Of C++
PPTX
C Programming Language Tutorial for beginners - JavaTpoint
PPT
2. data, operators, io
PDF
Deep C
C language
Reduce course notes class xii
Hands-on Introduction to the C Programming Language
C and C++ Industrial Training Jalandhar
Introduction Of C++
C Programming Language Tutorial for beginners - JavaTpoint
2. data, operators, io
Deep C

What's hot (20)

PPS
basics of C and c++ by eteaching
PPTX
Presentation on C++ Programming Language
PDF
Advanced C Language for Engineering
PPT
Csc1100 lecture01 ch01-pt1
PPT
Csc1100 lecture01 ch01-pt1
DOCX
Important C program of Balagurusamy Book
PPT
Introduction to C++
PDF
Programming with c language practical manual
DOCX
C Programming
PDF
Object-Oriented Programming in Modern C++. Borislav Stanimirov. CoreHard Spri...
PDF
Introduction to cpp
PPTX
Introduction to Basic C programming 02
PDF
C Programming
PPTX
C vs c++
PDF
VTU PCD Model Question Paper - Programming in C
PPT
C program
PPTX
Intro to c++
PPTX
Overview of c++ language
PPTX
C Programming Language Step by Step Part 1
basics of C and c++ by eteaching
Presentation on C++ Programming Language
Advanced C Language for Engineering
Csc1100 lecture01 ch01-pt1
Csc1100 lecture01 ch01-pt1
Important C program of Balagurusamy Book
Introduction to C++
Programming with c language practical manual
C Programming
Object-Oriented Programming in Modern C++. Borislav Stanimirov. CoreHard Spri...
Introduction to cpp
Introduction to Basic C programming 02
C Programming
C vs c++
VTU PCD Model Question Paper - Programming in C
C program
Intro to c++
Overview of c++ language
C Programming Language Step by Step Part 1
Ad

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

PPT
Data Types and Operators in C Programming
PPT
2. Data, Operators, IO in C Programing and its features
PPT
2. Data, Operators, IO (5).ppt
PPT
2. Data, Operators, IO.ppt
PPTX
Functions.pptx, programming language in c
PPTX
Introduction to c programming
PPT
Introduction to C Programming
PPT
Unit 4 Foc
PPTX
C introduction by thooyavan
PDF
C programing Tutorial
ODP
C prog ppt
PPT
The Basics of C - Math Functions and characters
PDF
C programming day#1
PPTX
c_pro_introduction.pptx
PPT
Fundamental of C Programming Language and Basic Input/Output Function
PDF
Introduction to programming c and data structures
PPT
Ch2 introduction to c
DOCX
C language tutorial
PPTX
C Programming Unit-1
Data Types and Operators in C Programming
2. Data, Operators, IO in C Programing and its features
2. Data, Operators, IO (5).ppt
2. Data, Operators, IO.ppt
Functions.pptx, programming language in c
Introduction to c programming
Introduction to C Programming
Unit 4 Foc
C introduction by thooyavan
C programing Tutorial
C prog ppt
The Basics of C - Math Functions and characters
C programming day#1
c_pro_introduction.pptx
Fundamental of C Programming Language and Basic Input/Output Function
Introduction to programming c and data structures
Ch2 introduction to c
C language tutorial
C Programming Unit-1
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Cloud computing and distributed systems.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Modernizing your data center with Dell and AMD
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Big Data Technologies - Introduction.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf
Cloud computing and distributed systems.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Network Security Unit 5.pdf for BCA BBA.
Mobile App Security Testing_ A Comprehensive Guide.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Modernizing your data center with Dell and AMD
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction
Chapter 3 Spatial Domain Image Processing.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Digital-Transformation-Roadmap-for-Companies.pptx
The AUB Centre for AI in Media Proposal.docx
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

2. data, operators, io

  • 1. 1 C PROGRAMMING LECTURE by Deepak Majeti M-Tech CSE mdeepak@iitk.ac.in 17th August C Course, Programming club, Fall 2008 IIT Kanpur
  • 2. Recap 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} C Course, Programming club, Fall 2008
  • 3. Some more basics 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 C Course, Programming club, Fall 2008
  • 4. My first C program! 4 #include <stdio.h> // program prints hello world int main() { printf ("Hello world!"); return 0; } Output: Hello world! C Course, Programming club, Fall 2008
  • 5. Example 1 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 C Course, Programming club, Fall 2008
  • 6. Example 2 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 C Course, Programming club, Fall 2008
  • 7. more and more 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; } C Course, Programming club, Fall 2008
  • 8. Note 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. C Course, Programming club, Fall 2008
  • 9. Some more Data Types 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 C Course, Programming club, Fall 2008
  • 10. Some more Arithmetic Operators 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; C Course, Programming club, Fall 2008
  • 11. Contd… 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 C Course, Programming club, Fall 2008
  • 12. Contd… 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 C Course, Programming club, Fall 2008
  • 13. Operator Precedence 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. C Course, Programming club, Fall 2008
  • 14. Precedence Table 14 Highest on top ++ -- (Postfix) ++ -- (Prefix) * / % + - << >> < > & | && || C Course, Programming club, Fall 2008
  • 15. Input / Output 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. C Course, Programming club, Fall 2008
  • 16. Some more geek stuff 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. C Course, Programming club, Fall 2008
  • 17. Home Work 17  Meaning of  Syntax  Semantics of a programming language  Find the Output:  value=value++ + value++;  Value=++value + ++value;  value=value++ + ++value; C Course, Programming club, Fall 2008
  • 18. End of Today’s Lecture 18 Doubts && Queries? C Course, Programming club, Fall 2008
  • 19. 19 THANK YOU C Course, Programming club, Fall 2008