SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
C             Programming
                       Language
               By:
    Yogendra Pal
yogendra@learnbywatch.com
  Dedicated to My mother and Father
t
                                                               y
         Keep your notebook with you.

Write important point and questions that comes in your mind

     Solve Mind band exercise.


                                                               C
                                       Rewind when not clear


              Ask Questions by call or SMS or by mail


Keep Watching Keep Learning

THIS IS C BASICS


                                   2
First C Program
• Print a line of text.
   #include<stdio.h>
   void main()
   {
          printf(“I am learning C”);
   }

• To compile you need a “C” compiler.
• Some compilers are Borland C, Turbo C.
                            3
Install Compiler
• Borland C and C++ compiler.
• Turbo C and C++ compiler.
• Work from
  – Command line interface (CLI).
  – Integrated Development Environment (IDE).




                         4
Mind Bend
• Type, compile and run the previous program
  on your computer.
• First use CLI then run them in IDE.
• C______ L___ I________.
• I_________ D__________ E__________.




                      5
C Character Set
• You write your C program by using some
  characters.
• These characters are:
  – Alphabets (Uppercase & Lowercase)
     • A,B,C…………………..,X,Y,Z.
     • a,b,c…………………...,x,y,z.
  – Digits (0,1,2,3,4,5,6,7,8,9)
  – Special symbols (~ ` ! @ # $ % ^ & * ( ) _ - + = |  } ] [
    {;:‘“/?.>,<)

                                6
C Character Set…




Alphabets
digits
Special Symbols
Space

                    7
Comments
• Comment a program for easy understanding.
• Two kind of comments are available
  – Single line comment
     • //
  – Multiple line comment
     • /*     */




                            8
Escape Sequence
  Character           Escape Sequence   ASCII value
   Newline                  n              10
Horizontal tab              t              9
 Vertical tab               v              11
  Backspace                 b              8
   Bell alert               a              7
Quotation mark              ”              34
 Apostrophe                 ’              39
Question mark               ?              63
  Backslash                               92
     Null                   0              0
Carriage return             r             013

                             9
Mind Bend
• Using escape sequence write a program that
  print following output (Use a single printf()
  function).
                          *
                         **
                        ***
                       *****
                      *******


                       10
Identifiers
• Identifiers are names given to Variables,
  Functions, arrays and other programming
  elements.
• Used to uniquely identify each element.
• Can contain alphabets, digits and underscore.
• First character must be an alphabet or
  underscore.
• Space and other special symbols are not
  allowed.
                       11
Identifiers…

A     o            V


         12
Identifiers…
           Correct                        Incorrect
 •   First_name                 •   First name
 •   a1                         •   1a
 •   area_of_circle             •   area-of-circle
 •   Pi                         •   ^
 •   TABLE                      •   “TABLE”
 •   _area                      •   -area
Try to make identifier meaningful and small.

                           13
Keywords
• Keywords are reserved words.
• Have standard, predefined meaning.
• Cannot be used as identifiers.




                      14
Keywords…
 auto      extern      sizeof    break      float
 static     case        for      struct     char
  goto     switch      const       if      sizedef
continue     int       union     default    long
unsigned     do       register    void     double
 return    volatile    else      short     while
 enum      signed


                         15
Data types
• There are several data types in C.
• Memory representation of each data type is
  different.
• Memory requirement is also different.
• Range of each data type varies from data type
  to data type.


                       16
Data Types…
•   Character (char)
•   Integer (int)
•   Floating point (float)
•   Double (double)
•   Valueless (void)



                             17
Character
• Character can be any single alphabet, digit or
  special symbol.
• There are total 256 characters.
• Value of character can be 0 to 255.
• 1 Character = 8 bits = 1 byte
• Represent with “char” in C programs.
• 8 bits means 28 = 256 possibilities.
• Format specifier : %c
                         18
Type Declaration
• Assign a data type to a variable.
• Declare a variable before use.
          char choice;
          char c1,c2,c3;
          char c1=‘y’;
          char c1=‘y’, c2=‘n’;



                           19
Input / Output instructions
• Output
  – printf(“ “);
  – printf(“format specifier”,variable);
     • printf(“%d”,i);
• Input
  – scanf(“format specifier”,&variable);
     • scanf(“%d”,&i);
  – scanf take input from console.
  – & operator represents the address.
                            20
Working with data
                                              No
• Create a variable of a data type.    c     value
   – char c;                           a
• Initialize it with a value.         1009

   – c = ‘a’;
• Use it in program.
   – printf ( “%c” , c);
• An example

                           21
Character constant
 • Single alphabet, digit or special symbol
   enclosed within single inverted comma.
 • Maximum length is one character.
 • Correct: ‘a’ ‘!’       ‘$’
 • Incorrect: a    ‘30’     30


Every character have a unique ASCII value.

                        22
Integer
• Integer can be any number.
• integer : 2 bytes (16 bit) or 4 bytes (32 bit).
  – 16 bit means 216 = 65536 numbers.
     • Range (-32768 to 32767)
  – 32 bit means 232 = 4,29,49,67,296 numbers.
     • Range (-2147483648 to 2147483647)
• Represent with “int” in C programs.
• Format specifier : %d
                             23
Working with integer
                                             No
                                            value
• Create a integer type variable.
                                    10
   – int i;
• Initialize it with a value.         2
   – i = 10;                        bytes

• Use it in program.
   – printf ( “%d” , i);
• An example

                           24
Integer Constant
• Must have at least one digit.
• Decimal point is not allowed.
• Can be positive or negative default is positive.
• Commas, blanks or any other symbol is not
  allowed.
• Correct: 12 -467 +098
• Incorrect: 12,120      12-10    13.09

                        25
Floating Point
• Floating number can be any number with
  decimal point.
• float : 4 bytes (32 bits)
  – Range (-3.4e38 to 3.4e38)
• Represent with “float” in C programs.
• Format specifier : %f


                          26
Float Constant
• Fractional form                       • Exponential form
   – eg. 456.09                           {mantissa, exponent}.
   – Must have at least one                – mantissaeexponent     eg.
     digit.                                  3.234e6
   – Must have a decimal                   – Both parts can be
     point.                                  positive or negative.
   – Positive or        negative           – Default sign is positive.
     default is positive.                  – Must have at least a
   – Comma, space and other                  single digit on both side
     special symbol is not                 – Exponent can not real.
     allowed.
                                   27
Mind Bend
• Are uppercase letters equivalent to lowercase
  letters? (yes/no)
• Can be use digits in an identifier name?
• Can be use any special character in identifier
  name?
• What are keywords?
• Write the range of character, integer and float
  data types used in C.

                        28
Mind Bend
• What are the escape sequences for newline,
  backspace and horizontal tab?
• What is the purpose of type declaration?
• Is declaration of each variable necessary
  before use?
• Can be use char as a variable name or
  identifier? CHAR can be used or not?

                     29
To get complete benefit of this tutorial solve all the quiz on
                       www.learnbywatch.com

              For any problem in this tutorial mail me at
                    yogendra@learnbywatch.com
                        with the subject “C”

                     For Other information mail at
                       info@learnbywatch.com


Keep Watching Keep Learning

NEXT IS ARITHMETIC INSTRUCTIONS

                                    30

Contenu connexe

Tendances (18)

Basic C Programming language
Basic C Programming languageBasic C Programming language
Basic C Programming language
 
Cbasic
CbasicCbasic
Cbasic
 
Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02
 
C++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer CentreC++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer Centre
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c language
 
C language basics
C language basicsC language basics
C language basics
 
An Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm ReviewAn Introduction To Python - Python Midterm Review
An Introduction To Python - Python Midterm Review
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
Javascript by Yahoo
Javascript by YahooJavascript by Yahoo
Javascript by Yahoo
 
Karakter dan String
Karakter dan StringKarakter dan String
Karakter dan String
 
C++ programming intro
C++ programming introC++ programming intro
C++ programming intro
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
Cbasic
CbasicCbasic
Cbasic
 
Intro to C++ - language
Intro to C++ - languageIntro to C++ - language
Intro to C++ - language
 
Introduction
IntroductionIntroduction
Introduction
 
c++
 c++  c++
c++
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variables
 

Similaire à C basics (20)

Programming in c
Programming in cProgramming in c
Programming in c
 
C PROGRAMING.pptx
C PROGRAMING.pptxC PROGRAMING.pptx
C PROGRAMING.pptx
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Cpu
CpuCpu
Cpu
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 
C PADHLO FRANDS.pdf
C PADHLO FRANDS.pdfC PADHLO FRANDS.pdf
C PADHLO FRANDS.pdf
 
All C ppt.ppt
All C ppt.pptAll C ppt.ppt
All C ppt.ppt
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
 
Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_language
 
Chap 1 and 2
Chap 1 and 2Chap 1 and 2
Chap 1 and 2
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in C
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
20BCT23 – PYTHON PROGRAMMING.pptx
20BCT23 – PYTHON PROGRAMMING.pptx20BCT23 – PYTHON PROGRAMMING.pptx
20BCT23 – PYTHON PROGRAMMING.pptx
 
Introduction to C
Introduction to CIntroduction to C
Introduction to C
 
Lec08-CS110 Computational Engineering
Lec08-CS110 Computational EngineeringLec08-CS110 Computational Engineering
Lec08-CS110 Computational Engineering
 
COMPUTER PROGRAMMING
COMPUTER PROGRAMMINGCOMPUTER PROGRAMMING
COMPUTER PROGRAMMING
 
Chapter02.PPT
Chapter02.PPTChapter02.PPT
Chapter02.PPT
 
c programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPTc programming 2nd chapter pdf.PPT
c programming 2nd chapter pdf.PPT
 
Introduction to Problem Solving C Programming
Introduction to Problem Solving C ProgrammingIntroduction to Problem Solving C Programming
Introduction to Problem Solving C Programming
 

Plus de Learn By Watch

Demodulation of fm pll detector
Demodulation of fm pll detectorDemodulation of fm pll detector
Demodulation of fm pll detectorLearn By Watch
 
Demodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorDemodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorLearn By Watch
 
In direct method of fm generation armstrong method
In direct method of fm generation armstrong methodIn direct method of fm generation armstrong method
In direct method of fm generation armstrong methodLearn By Watch
 
Direct method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodDirect method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodLearn By Watch
 
Spectrum and power of wbfm
Spectrum and power of wbfmSpectrum and power of wbfm
Spectrum and power of wbfmLearn By Watch
 
Narrow band frequency modulation nbfm
Narrow band frequency modulation nbfmNarrow band frequency modulation nbfm
Narrow band frequency modulation nbfmLearn By Watch
 
General expression of fm signal
General expression of fm signalGeneral expression of fm signal
General expression of fm signalLearn By Watch
 
Frequency division multiplexing
Frequency division multiplexingFrequency division multiplexing
Frequency division multiplexingLearn By Watch
 
Demodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorDemodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorLearn By Watch
 
Generarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodGenerarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodLearn By Watch
 
Generarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodGenerarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodLearn By Watch
 
Demodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverDemodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverLearn By Watch
 
Quadrature carrier multiplexing qam
Quadrature carrier multiplexing qamQuadrature carrier multiplexing qam
Quadrature carrier multiplexing qamLearn By Watch
 
Demodulation of am synchronous detector
Demodulation of am synchronous detectorDemodulation of am synchronous detector
Demodulation of am synchronous detectorLearn By Watch
 

Plus de Learn By Watch (20)

Tutorial 9 fm
Tutorial 9 fmTutorial 9 fm
Tutorial 9 fm
 
Phase modulation
Phase modulationPhase modulation
Phase modulation
 
Demodulation of fm pll detector
Demodulation of fm pll detectorDemodulation of fm pll detector
Demodulation of fm pll detector
 
Demodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorDemodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detector
 
In direct method of fm generation armstrong method
In direct method of fm generation armstrong methodIn direct method of fm generation armstrong method
In direct method of fm generation armstrong method
 
Direct method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodDirect method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator method
 
Carson's rule
Carson's ruleCarson's rule
Carson's rule
 
Spectrum and power of wbfm
Spectrum and power of wbfmSpectrum and power of wbfm
Spectrum and power of wbfm
 
Narrow band frequency modulation nbfm
Narrow band frequency modulation nbfmNarrow band frequency modulation nbfm
Narrow band frequency modulation nbfm
 
General expression of fm signal
General expression of fm signalGeneral expression of fm signal
General expression of fm signal
 
Angle modulation
Angle modulationAngle modulation
Angle modulation
 
Frequency division multiplexing
Frequency division multiplexingFrequency division multiplexing
Frequency division multiplexing
 
Vsb modulation
Vsb modulationVsb modulation
Vsb modulation
 
Demodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorDemodulation of ssb synchronous detector
Demodulation of ssb synchronous detector
 
Generarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodGenerarion of ssb phase discrimination method
Generarion of ssb phase discrimination method
 
Generarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodGenerarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination method
 
Ssb modulation
Ssb modulationSsb modulation
Ssb modulation
 
Demodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverDemodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiver
 
Quadrature carrier multiplexing qam
Quadrature carrier multiplexing qamQuadrature carrier multiplexing qam
Quadrature carrier multiplexing qam
 
Demodulation of am synchronous detector
Demodulation of am synchronous detectorDemodulation of am synchronous detector
Demodulation of am synchronous detector
 

C basics

  • 1. C Programming Language By: Yogendra Pal yogendra@learnbywatch.com Dedicated to My mother and Father
  • 2. t y Keep your notebook with you. Write important point and questions that comes in your mind Solve Mind band exercise. C Rewind when not clear Ask Questions by call or SMS or by mail Keep Watching Keep Learning THIS IS C BASICS 2
  • 3. First C Program • Print a line of text. #include<stdio.h> void main() { printf(“I am learning C”); } • To compile you need a “C” compiler. • Some compilers are Borland C, Turbo C. 3
  • 4. Install Compiler • Borland C and C++ compiler. • Turbo C and C++ compiler. • Work from – Command line interface (CLI). – Integrated Development Environment (IDE). 4
  • 5. Mind Bend • Type, compile and run the previous program on your computer. • First use CLI then run them in IDE. • C______ L___ I________. • I_________ D__________ E__________. 5
  • 6. C Character Set • You write your C program by using some characters. • These characters are: – Alphabets (Uppercase & Lowercase) • A,B,C…………………..,X,Y,Z. • a,b,c…………………...,x,y,z. – Digits (0,1,2,3,4,5,6,7,8,9) – Special symbols (~ ` ! @ # $ % ^ & * ( ) _ - + = | } ] [ {;:‘“/?.>,<) 6
  • 8. Comments • Comment a program for easy understanding. • Two kind of comments are available – Single line comment • // – Multiple line comment • /* */ 8
  • 9. Escape Sequence Character Escape Sequence ASCII value Newline n 10 Horizontal tab t 9 Vertical tab v 11 Backspace b 8 Bell alert a 7 Quotation mark ” 34 Apostrophe ’ 39 Question mark ? 63 Backslash 92 Null 0 0 Carriage return r 013 9
  • 10. Mind Bend • Using escape sequence write a program that print following output (Use a single printf() function). * ** *** ***** ******* 10
  • 11. Identifiers • Identifiers are names given to Variables, Functions, arrays and other programming elements. • Used to uniquely identify each element. • Can contain alphabets, digits and underscore. • First character must be an alphabet or underscore. • Space and other special symbols are not allowed. 11
  • 13. Identifiers… Correct Incorrect • First_name • First name • a1 • 1a • area_of_circle • area-of-circle • Pi • ^ • TABLE • “TABLE” • _area • -area Try to make identifier meaningful and small. 13
  • 14. Keywords • Keywords are reserved words. • Have standard, predefined meaning. • Cannot be used as identifiers. 14
  • 15. Keywords… auto extern sizeof break float static case for struct char goto switch const if sizedef continue int union default long unsigned do register void double return volatile else short while enum signed 15
  • 16. Data types • There are several data types in C. • Memory representation of each data type is different. • Memory requirement is also different. • Range of each data type varies from data type to data type. 16
  • 17. Data Types… • Character (char) • Integer (int) • Floating point (float) • Double (double) • Valueless (void) 17
  • 18. Character • Character can be any single alphabet, digit or special symbol. • There are total 256 characters. • Value of character can be 0 to 255. • 1 Character = 8 bits = 1 byte • Represent with “char” in C programs. • 8 bits means 28 = 256 possibilities. • Format specifier : %c 18
  • 19. Type Declaration • Assign a data type to a variable. • Declare a variable before use. char choice; char c1,c2,c3; char c1=‘y’; char c1=‘y’, c2=‘n’; 19
  • 20. Input / Output instructions • Output – printf(“ “); – printf(“format specifier”,variable); • printf(“%d”,i); • Input – scanf(“format specifier”,&variable); • scanf(“%d”,&i); – scanf take input from console. – & operator represents the address. 20
  • 21. Working with data No • Create a variable of a data type. c value – char c; a • Initialize it with a value. 1009 – c = ‘a’; • Use it in program. – printf ( “%c” , c); • An example 21
  • 22. Character constant • Single alphabet, digit or special symbol enclosed within single inverted comma. • Maximum length is one character. • Correct: ‘a’ ‘!’ ‘$’ • Incorrect: a ‘30’ 30 Every character have a unique ASCII value. 22
  • 23. Integer • Integer can be any number. • integer : 2 bytes (16 bit) or 4 bytes (32 bit). – 16 bit means 216 = 65536 numbers. • Range (-32768 to 32767) – 32 bit means 232 = 4,29,49,67,296 numbers. • Range (-2147483648 to 2147483647) • Represent with “int” in C programs. • Format specifier : %d 23
  • 24. Working with integer No value • Create a integer type variable. 10 – int i; • Initialize it with a value. 2 – i = 10; bytes • Use it in program. – printf ( “%d” , i); • An example 24
  • 25. Integer Constant • Must have at least one digit. • Decimal point is not allowed. • Can be positive or negative default is positive. • Commas, blanks or any other symbol is not allowed. • Correct: 12 -467 +098 • Incorrect: 12,120 12-10 13.09 25
  • 26. Floating Point • Floating number can be any number with decimal point. • float : 4 bytes (32 bits) – Range (-3.4e38 to 3.4e38) • Represent with “float” in C programs. • Format specifier : %f 26
  • 27. Float Constant • Fractional form • Exponential form – eg. 456.09 {mantissa, exponent}. – Must have at least one – mantissaeexponent eg. digit. 3.234e6 – Must have a decimal – Both parts can be point. positive or negative. – Positive or negative – Default sign is positive. default is positive. – Must have at least a – Comma, space and other single digit on both side special symbol is not – Exponent can not real. allowed. 27
  • 28. Mind Bend • Are uppercase letters equivalent to lowercase letters? (yes/no) • Can be use digits in an identifier name? • Can be use any special character in identifier name? • What are keywords? • Write the range of character, integer and float data types used in C. 28
  • 29. Mind Bend • What are the escape sequences for newline, backspace and horizontal tab? • What is the purpose of type declaration? • Is declaration of each variable necessary before use? • Can be use char as a variable name or identifier? CHAR can be used or not? 29
  • 30. To get complete benefit of this tutorial solve all the quiz on www.learnbywatch.com For any problem in this tutorial mail me at yogendra@learnbywatch.com with the subject “C” For Other information mail at info@learnbywatch.com Keep Watching Keep Learning NEXT IS ARITHMETIC INSTRUCTIONS 30