Contents
- How C
program gets executed
- C
Tokens
- Variables
- Primary
Data Types
How the program gets executed
- Enter
the program using any editor
- Edit
the source program
- Compile
the code
- If
syntax error exists then edit the program again
- If
syntax error does not exist then Object code is created (filename.obj)
- Execute
the Object code and check input data
- The
code check for errors
- If
Logic error exists then edit the program
- If
Data error exists input data is again given to the program
- If
code is error free then output appears on screen
•In a passage individual words and
punctuation marks are called as tokens
•In C individual units are called Tokens
32 Keywords in C!!
- Keywords are words whose meaning is already explained to C Compiler
- Must be written in lowercase letters
Identifiers!!
Identifiers are user-defined words and is used to give names to entities like
- Variables
- Arrays
- Functions
- Structures
Rules for Naming Identifiers
The name should consist of only
Alphabets
(A,B…..Z or a,b……z)
Digits
(0,1…..9)
Underscore
sign (_)
First character should be an alphabet or underscore
The name should not be a keyword
Code, code and CODE are three different identifiers
Length
- Some compilers recognize 31 characters
Constants
Integer Constants
Integer constants refers to sequence of
digits
Three types of integer constants
- Decimal
(base 10)
- Octal (base 8)
- Hexadecimal
(base 16)
Integer constants refers to sequence of digits
Three types of integer constants
Rules for Integer Constants
Must have at-least one digit
Must not have a decimal (.) point
Can be either +ve or –ve
No commas or blanks are allowed
Allowable range is -32768
to 32767 for
16 bit compiler
Must have at-least one digit
Must not have a decimal (.) point
Can be either +ve or –ve
No commas or blanks are allowed
Allowable range is -32768 to 32767 for 16 bit compiler
Ex:
Real Constant
Also known as floating point constants
Contains decimal point
Two forms of real constants
- Fractional
- Exponential
Rules for Fractional Form
- Must have atleast one digit
- Have a decimal point
- Either +ve or –ve
- No commas or blanks are allowed
- Ex:
Rules for Exponential Form
The constant is divided into two parts
- The part appearing before e is called mantissa
- The part following e is called exponent
The mantissa and exponent is separated by
letter e
Mantissa may have +ve or –ve sign
Exponent must have at-least one
digit
Exponent may have +ve or –ve
Character Constant
Is a single alphabet, digit or special symbol enclosed within single inverted commas (‘’)
Maximum length can be 1 character
Ex
- ‘A’
- ‘1’
- ‘5’
- ‘$’
Backslash Character Constant
String Constant
Sequence of characters enclosed in double quotes (“”)
‘X’ ≠ “X”
Ex
- “Hello!”
- “987”
- “%% &*”
- “5+4”
Special Symbols
Also known as Delimiters
Operators
Operator specifies an operation to be performed
Variables
Variable is a name used to store values
Values assigned to variable can be changed during execution of a program
Data Types
- A
type is a collection of values with shared properties
- Using
types makes a program easier to read and understand
- Using
types makes it easier for the compiler
- Types
makes it easier to detect certain programming errors
Classes of Data Types
- Primary
(Fundamental) Data Types
- User-defined
Data Types
- Derived
data types
- Empty
Data set
Primary Data Types
Use of Qualifiers
Range of Data Types
Example
#include<stdio.h>
main()
{
int a, b, c, d; //declaration
unsigned u = 10;
//declaration
a = 12; b = -24;
//assignment
c = a + u; d = b + u;
//assignment
printf(“a+u=%d, b+u=%d\n”, c, d);
}
output:
a+u=22, b+u=-14
See you in the next post.....
No comments:
Post a Comment