Lecture
Introduction on c language
1.C is a general purpose programming language . It has been
closely associated with the unix. System since it was
developed on that system and although it has been called a
system programming language.
2.C is a relatively low level language. This characterization is
not pejorative. It simply means that C deals with the same
sort of Objects that most computers do.
3.C. offers only straightforward. Single thread control flow
constructions. Tests, loops grouping ,and subprograms , but
not multi- programming. Parallel operations , synchronization
or co routines.
4.Although C matches the capabilities of many computers , it is
independent of any particular machine architecture , and so
with a little care it is easy to write portable programs that is
programs which can be run without change on a variety of
hardware .
5.In C. the fundamental data Objects are characters , integers of
several sizes , and floating point numbers, in addition, there is
a hierarchy of derived data types created with pointers ,
arrays , structures , unions , and functions .
6.C Provides the fundamental flow. Control constructions
required for well- structured programs. Statement grouping .
decisions makings (if); looping , with the termination test at
the top ( while for ) . or at the bottom (do) , and selecting one
of a set of possible case ( switch).
7.C provides pointers and the ability to do address arithmetic.
arguments to functions are passed by copying the value of the
argument and it is impossible for the called function to
change the actual argument in the caller.
8. In C any function may be called recursively, and its, local
variables are typically automatic or created anew with each
invocation. Function definitions my not be nested but variables
may be declared in a block structured fashion.
9. is a compact language based on a few fundamental ideas.
a)A c program is no more than a function which can
contain other function.
b)There is distinction between the form of an action and
the result of that action.
c)Computer memory is organized in an explicity
sequential manner for use the c programmer sequential
manner for use the c programmer.
For the above review. We can obtain some point to why we
selection the c. language .
a)C. language it is multipurpose and development can be
done.
b)C language properly with computer eng.. Since.
c)C language is the unix. Language operating system.
Function in C
1)A c program is a set of functions , all of which have
an action and all of which C. produce a result. A
function always neutrons a value. Thought the value
returned may be designated as void ( that is , no value
is returned by the function has only an action).
2)Function which are combined to produce an operative
C program need not all be in the same file, In normal
need not all be in the same file, In normal program
environments most C programs are produced by
linking together functions from many file.
3)One of the file must contain a function known as "
main " in fact , a C program is a main function calls
other functions, when a C program is executed C
system looks for a function with the name main , and
exaction always starts with the main function. If there
is no main function , by definition , there is program
to execute.
4).Every function used in a C program has an action and
produces a numerical result ( even if the result is void )
For example , the C statement printf ( " % d" , 4);
Refers to a function printf , which will print the number 4
on the console " screen " as a decimal integer, as a result of the
string " % d" , printf is a function with a specific form of a
action. The statement. Printf ( " % d" , a var= 4);.
Will not only out the number 4 , but wills also assign the
Value 4 to the variable named a Var. the action the statement a
Var= 4 is an assignment an the result. of the assignment is the
value 4.
The action of the printf function in the case of .
Print f ( " who are you?");
It to print the question who are you ? , and the result of the
action is to provide a value equal the number of characters
printed. It is possible. To assign the value , which result. from
the action of the function , to a variable thus.
a Var = printf(" who are you?");
Will print the question, and also assign a value to a var (
equal to the number of characters printed),
The arrangement of Memory
The C language organizes computer storage as a sequence
of memory location. Known as bytes. A name ( or identifier ) of
a variable or function refers to a specific number of consecutive
bytes , where the number of bytes is determined by the
declaration of the types of a c item , it is important to distinguish
between.
The name of an item .
*In the case of a variable , the name refers to the value of the
variable , as stored in the appropriate locations.
*In the case of a function the name refers not only the value
returned by the function, but also to the sequence of actions
produced by the function.
*The address of the first of the consecutive locations in
which the value is stored .
*The value of a variable stored in a sequence of locations
stating at a specified address.
*The definition of a function which determine the
instructions stored in a sequence of locations starting at a
specified address.
Simple C programs
Start by looking at the simplest c program which is
probably.
main ( )
{ }
Program which does nothing.
The are two parts to the simple program:
*Main (c) this line declares a function called main, the
c translator knows that main is a function because the
name is followed by the parentheses {}.
*{ } this line defines the action of the main function
declared in the previous line.
The definition is empty, thus main has no action , and
produces no result.
A more complex ( less simple ) program is
# Include < stdio. h>
main ( )
{
Printf ( " who are you ? \ n");
}
Which print
Who are you ?
on the screen. The principle change we have made tot the
simplest program is to the definition of the main( ) function ,
which now contains a friendly enquiry. That is
Printf( " who are you ? \n")
The portion of program between { and } is commonly
termed a block and within any block the separate statements are
terminated by a semicolon. The change to the definition of main
( ) is reflected in anther change , that is ,the new line.
# include < stdio. h>
An instruction of the c translator to include information
from file known as stdio. h. the new information is needed to
accommodate the function printf( ) used in the main ( )
function definition. Within the file stdio.h is there a declaration
of printf().