What is C?
C is a computer oriented, procedural, general purpose,
middle-level, modular, compact, portable, case sensitive, loosely typed, high
speed and power full programming language.
C language fundamentals:
Learning of any language involves some procedural steps that
are learning characters, words and sentences.
Characters used in C language are called C character set.
Combination of characters is called a token. Combination of words is called a
statement.
C character set:
Set of characters used in C language is called C character
set.
It includes Alphabets, digits and special symbols.
Alphabets: A to Z, a to z Digits: 0 to 9 Special symbols: ! # & % () {} + - * etc.
C Tokens:
Combination of characters or a word in C language is called
a C Token.
According to the usage, these are classified into
Key words
Constants
Identifiers
Operators
Keywords:
These are the special words used in C-Language.
Every word has its purpose and grammar in using.
There are totally 32 key words used in C-Language.
Keywords are always written in small case, because C is a
case sensitive language.
Example:
int
fir;
Example explained:
int is a keyword used to allocate a part of memory (RAM or
main memory) to store an integer constant.
Example:
float
price;
Example explained:
float is a keyword used to allocate a part of memory (RAM or
main memory) to store a real constant.
Constants:
These are the values stored in the computer memory.
These values may be assigned by the user or by the program.
According to the nature of data, constants are classified
into
Note:
An octal number must be pre-fixed with 0 (zero).
A hex-decimal number must be prefixed with 0X (zero ex).
Single character constant must be placed with in single
quotations.
A word or a string must be placed with in double quotations.
Constants
Example:
float price;
price=25.750000;
Identifiers:
Identifier is the name of a variable (memory allocation), an
array, a function or a pointer.
Note: array, function and pointers are discoursed later.
The following rules must be followed while selecting an
identifier.
Length of identifier must not exceed to 31 characters.
(According to ANSI C).
First character must not be a digit.
Space characters can’t be used.
Key words can’t be used as identifiers.
Special symbols can’t be used. (Underscore is accepted).
Example:
float price=25.750000;
Valid and Invalid examples:
price valid
net salary invalid
(space character cannot be used)
gross_sal valid
Int valid
(it is not a keyword, because keywords must be writer in small case)
float invalid
(it is a keyword)
1st invalid
(1st character must not be a digit)
no1 valid
Operators:
Operator is a symbol that tells the computer to perform some
arithmetic, relational or logical operations.
Operators are user to manipulate the data.
C language is rich in operators.
Operators in C language are classified into.
Arithmetic operators (+ - * / %)
Relational operators (< > <= >= == !=)
Logical operators (&& ||!)
Assigning operator (=)
Conditional or turnery operators (? :)
Increment/Decrement operator (++ --)
Bit-wise operators (~ & | << >> ^)
Pointer operators (& *
*. ->)
Typecast operator (type)
Direct member access operator(.)
Short-cut operators (+=
-= *= /= %=)
Special operator (sizeof, comma operator, # , ## etc.)
Assigning operator:
‘=’ is a unary operator used to assign a constant or a value
of an expression to the variable.
Example:
Example:
Example:
Arithmetic operators:
Arithmetic operators are the binary operators used to write
the arithmetic expressions.
C language has the following arithmetic operators.
Operator purpose
+ Addition
- Subs traction
* Product
/ Division
% Mod
Mod (%): It looks like a percentage operator, but works
differently in C language. It is called mod operator in C language, used to get
the remainder of an expression.
Examples:
Arithmetic expression:
Combination of arithmetic operators, constants, variables is
called an arithmetic expression.
Example:
Evaluation or execution of arithmetic expression happens
according to the priority of arithmetic operators
Computer may be of any speed, only a single operator
executes at a time.
The priority or presidency of arithmetic operators is
Operators Priority
( ) 1st
* / % 2nd
+ - 3rd
= Last
priority
Example:
Example explained:
Pass1: First priority
goes to the (), so (5+2) executes.
Pass2: Though / * %
have the same priority, / appears first, so 4/2 executes.
Pass3: Though * %
have the same priority, * appears first, so 8*4 executes.
Pass4: % gets the
higher priority, so 7%3 executes.
Pass5: Though + - have the same priority, + appears first,
so 2+32 executes.
Pass6: - gets the higher priority, so 34-1 executes.
Pass7: = gets the least priority, so 33 is assigned to X
0 comments:
Post a Comment