C             Programming
                       Language
               By:
    Yogendra Pal
yogendra@learnbywatch.com
  ...
t
                                                               y
         Keep your notebook with you.

Write important ...
First C Program
• Print a line of text.
   #include<stdio.h>
   void main()
   {
          printf(“I am learning C”);
   }...
Install Compiler
• Borland C and C++ compiler.
• Turbo C and C++ compiler.
• Work from
  – Command line interface (CLI).
 ...
Mind Bend
• Type, compile and run the previous program
  on your computer.
• First use CLI then run them in IDE.
• C______...
C Character Set
• You write your C program by using some
  characters.
• These characters are:
  – Alphabets (Uppercase & ...
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
     • /...
Escape Sequence
  Character           Escape Sequence   ASCII value
   Newline                  n              10
Horizont...
Mind Bend
• Using escape sequence write a program that
  print following output (Use a single printf()
  function).
      ...
Identifiers
• Identifiers are names given to Variables,
  Functions, arrays and other programming
  elements.
• Used to un...
Identifiers…

A     o            V


         12
Identifiers…
           Correct                        Incorrect
 •   First_name                 •   First name
 •   a1   ...
Keywords
• Keywords are reserved words.
• Have standard, predefined meaning.
• Cannot be used as identifiers.




        ...
Keywords…
 auto      extern      sizeof    break      float
 static     case        for      struct     char
  goto     sw...
Data types
• There are several data types in C.
• Memory representation of each data type is
  different.
• Memory require...
Data Types…
•   Character (char)
•   Integer (int)
•   Floating point (float)
•   Double (double)
•   Valueless (void)



...
Character
• Character can be any single alphabet, digit or
  special symbol.
• There are total 256 characters.
• Value of ...
Type Declaration
• Assign a data type to a variable.
• Declare a variable before use.
          char choice;
          cha...
Input / Output instructions
• Output
  – printf(“ “);
  – printf(“format specifier”,variable);
     • printf(“%d”,i);
• In...
Working with data
                                              No
• Create a variable of a data type.    c     value
   –...
Character constant
 • Single alphabet, digit or special symbol
   enclosed within single inverted comma.
 • Maximum length...
Integer
• Integer can be any number.
• integer : 2 bytes (16 bit) or 4 bytes (32 bit).
  – 16 bit means 216 = 65536 number...
Working with integer
                                             No
                                            value
• C...
Integer Constant
• Must have at least one digit.
• Decimal point is not allowed.
• Can be positive or negative default is ...
Floating Point
• Floating number can be any number with
  decimal point.
• float : 4 bytes (32 bits)
  – Range (-3.4e38 to...
Float Constant
• Fractional form                       • Exponential form
   – eg. 456.09                           {manti...
Mind Bend
• Are uppercase letters equivalent to lowercase
  letters? (yes/no)
• Can be use digits in an identifier name?
•...
Mind Bend
• What are the escape sequences for newline,
  backspace and horizontal tab?
• What is the purpose of type decla...
To get complete benefit of this tutorial solve all the quiz on
                       www.learnbywatch.com

              ...
Upcoming SlideShare
Loading in...5
×

C basics

1,494

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,494
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
103
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

C basics

  1. 1. C Programming Language By: Yogendra Pal yogendra@learnbywatch.com Dedicated to My mother and Father
  2. 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. 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. 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. 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. 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
  7. 7. C Character Set… Alphabets digits Special Symbols Space 7
  8. 8. Comments • Comment a program for easy understanding. • Two kind of comments are available – Single line comment • // – Multiple line comment • /* */ 8
  9. 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. 10. Mind Bend • Using escape sequence write a program that print following output (Use a single printf() function). * ** *** ***** ******* 10
  11. 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
  12. 12. Identifiers… A o V 12
  13. 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. 14. Keywords • Keywords are reserved words. • Have standard, predefined meaning. • Cannot be used as identifiers. 14
  15. 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. 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. 17. Data Types… • Character (char) • Integer (int) • Floating point (float) • Double (double) • Valueless (void) 17
  18. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×