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
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