Programming in C:
C is a middle level structure and procedural programming language is developed at "Bell Laboratory" (AT and T) in the year 1972 by "DENNIS RITCHIE".
Turbo 'C' was developed by borland international in the year 1989.
'C' character set :
- Alphabets (both in upper and lower case).
- Digits (0 - 9)
- Special symbols ( !, #, &, $, +, -, =, <, >, {}, [], @, ;, etc)
'C' data types:
1) primary data types - (character, integer, floating point, long integer, double, void)
2) secondary data types - (array, pointer, etc)
3) user-defined data types - (structure, union, enum etc).
'C' data types, 'C' prefix and conversion specification:
Data type | ‘C’ prefix | Conversion specification |
character | char | %c |
integer | int | %d |
floating point | float | %f |
long integer | long | %ld |
double | double | %lf |
void | void | 0 |
Example of a program:
C Tokens and its Types:
Each and every smallest individual unit in a C program are known as C tokens.
C tokens are the basic building blocks in a C language which are constructed together to write a C program.
Types-
C tokens are 6 types -
- Identifier
- Constant
- String
- Special symbols
- Keywords
- Operators
1. Identifier -
Each C program elements are given a name called identifier.
Names are given to identify variable, functions, array etc.
Rules for constructing identifier:-
- First character must be an alphabet.
- Identifiers shouldn't be keywords.
- Punctuation on a special character are not allowed except underscore.
- Most identifiers are in lower case letter.
2. Constant -
Any value reference to constant.
Variable :-
Variable is the name given to computer memory cell where we can store constant.
3. String :-
Collection of character enclose with a pair of (" ") ( double quate) is known as string.
4. Special symbols :-
( +, -, =, < , >, @, !, #, ; , $, [], ) are special symbols.
Escape sequence character :-
These are non printing characters use for special operations inside a program.
\o = lulu
\n = new line
\" = double quate
\' = single quate
\b = back space
\t = horizontal tab
\v = vertical tab
\\ = back slash
5. Keywords :-
Keywords are print find words in C compiler. These words have fix meaning and cannot be changed.
C language supports 32 keywords which are given below :-
auto |
double |
int |
struct |
break |
case |
long |
switch |
case |
enum |
register |
typedof |
char |
extern |
return |
union |
const |
float |
short |
unsigned |
continue |
for |
signed |
void |
default |
goto |
sizeof |
volatile |
do |
if |
static |
while |
6. Operators :-
Operators are the special symbols use for the specific operation inside the expression.
Expression :-
Constant, variable and function reference are joined together by various operators to form expression.
Example -
C=X + 3 ;
( here '+' is operator)
Types of operators :-
Operators are 6 types -
- arithmetical operator - ( + , - , / , % ,)
- assignment operator - (= , += , -= , \=)
- relation operator - (< , > , <= , >= , ==)
- logical operator - (&& (and) , ||(or) , >! (not) )
- increment &decrement operator- (++, --)
- conditional or ternary operator - (?, :)
- size of operator- ( )
- bitwise operator - ( << , >> , & , ^)
Statement use in 'C' language:
The statement are real building blocks of a C program. We can impliment our logic through different type of statement.
Basically statement is two types :
- Non executable statement
- Executable statement.
- Non executable statement : Non executable statement are not compiled with C compiler. This is for program reference.
- Executable statement : Executable statement are compiled with C compiler.
Executable statement basically 5 types :
- Declaration statement : use to the declaration of variables, functions, modules to be use in program.
- Input / output statement : use to get input and give output to the program.
- Conditional statement : use to execution of program based on condition.
- Iteration statement : continue execution of statement.
- Operational statement : use to the execution of different operations through variable and operators.
Rules to write a C program :
2. Each C program should be at least one function i.e main function / main ( ).
3. Statements are written inside { }.
4. Each statement should be ended with (;).
Syntax :
- # include < stdio. h >
- # include < conio. h >
- # include < math. h >
- # include < string. h >
- # include < graphics. h > etc
- A single line comment starts with //
- A multi line comment starts with /* and ends with */
Functions use in 'C' language:
Functions are predefined procedure and calculations which are already named for a easy use.
Type of functions :
- library function
- user defined function
- print f ( )
- scan f ( )
- clrscr ( )
- getch ( )
- main ( ) etc
- function definition
- function declaration
- function calling
No comments:
Post a Comment