Professional Documents
Culture Documents
DE.2017/4579
given
by
Dr. Benneth
This is written to explain the basic feature of C programming language in comparison to other
programming languages like Prolog, C++, Java, Php, Python etc, because of the need for the
understanding of the way programming languages are being organized and to be able to figure out
the general behaviour of every programming language, the need to understand each of them
basically is required. This has sharpened my programming skill and I was able to face C
programming by force which I found so intresting.
TABLE OF CONTENT
C PROGRAMMING ENVIRONMENT
Syntax:
main()
.................
..................
.................
C FUNCTIONS
They are small unit of program used to carryout specific task. Function
is basically a set of statement that takes inputs, perform some computation
and produces output, function is used in a program for the following reasons:
Reusability: Once a function is defined, it can be reused over and over
again.
Abstraction: If you are just using the function in your program then you
don’t about how it works inside, example: scanf function
return_type: In C return_type can of any data types like int, double, char,
void, short e.t.c
Function_name: They are just any meaning names that can be easy to
understand the purpose of the function just by seeing the name.
Argument List/Parameters: This contains variables names along with their
data types.
Block of code: Set of C statements, which will be executed whenever a call
will be made to the function.
COMMENTS
Comments are use to explain what is going on ina program or code. They are
something like notes in the code. Comments are used to explain code logic
so that we can be able to understand the code later, other developers can be
able to read and understand the code easily. Comments are used to increase
Readability and Understandability of the source code. They are use for
documentation.
In terms of Program Maintainance which is the process of changing a
program over time to fix hidden bugs and to adapt the program to changing
environment, comment speeds program maintainance.
In C language every comment in your program are for the people and
the programming statement residing outside the comments are for the
computer.
Comments are not C commands.
Comments can also be used as a testing purpose, you might find it
useful to comment out a section of a code by putting /* and */ around it,.
By doing this you cause C to ignore that particular section of code.
Comment cannot be nested, embed one comment within another.
WHITESPACE
Whitespace are blank line and spaces you find in many programs, in
making your program readable, whitespace is more important than comment.
However, writting a program without giving space when needed will leads to
confusion, In c whitespace is used in the arrangement of statement or
program statement to enhance readability. The inclusion of whitespace and
line breaks help in the understanding of codes.
DELIMETERS
They are one or more characters that separate text strings. There are
different type of delimeters and the common ones are:
Commas ( , ): Used to separate variables
Semicolon ( ; ): Used to Terminate statement
Colon ( : ): Use for label
Quotes ( “, ‘ ): Used create string in the program
Curly Braces ( { } ): Used for scope of statement
Hash ( # ) : Used as a preprocessor directive
Square Bracket ( [ ] ): Used for any array declaration
Angle Bracket ( <> ): Header File
DATA TYPES
In C Data types are refered to as an extensive system used for
declaring variable or functions of different types. Data types tells the type data
that is stored in a variable and how much memory should be allocated to the
data.The type of variable determine the space it will occupy in th storage and
how bit pattern stored interpreted. Data type specify how we enter data into
our program and what type of data we enter. Data types can be classified as
follow:
Primary/Basic/foundamental Data Type
Derived Data Type
Use-define Data Type
Floating Point (float): They are used to store real numbers, i.e Decimal
numbers
Size on 16-bit machine:
float 4 bytes
double 8 bytes
long double 10 bytes
Void Type: This means no value and it is usually to specify the type of
functions which return nothing.
Derived Data Types: They are also a primary data types but a little twisted or
grouped together, and they are:
a) Array
b) Structure
c) Union
d) Pointer
Array: They are the most used Derived Data Types in C, and they can be
formed by collecting the primitive data types, like float, int, char. So the
collection of any of these data type then form an array. The size of an array is
dtermined by it’s initialization.
Structure: Also one of the Derived Data Types in C, they are collections of
different data type items stored in a connecting memory allocation.
Union: It is also a Derived Data Type in C, and they are much like structure
but the amount of memory used by them is equivalent to the size of union
member which took maximum storage space. A union type can store objects
of different type at the same location in memory.
Pointer: Pointer are fourth type of Derived Data Type in C, though the size
that they take in a memory is always fix but the type of pointer depends on
the type element whose address they store.
User-define Data Type: They defined by the user, and they are:
a) Typedef Data
b) Enumarated
Typedef: The keywoard is used to create new name for an existing data
type.
Syntax:
typedef existing_type.
VARIABLES
In C programming variable is simply a name that point to some memory
loation by simply using the name of any choice. Variable must be declared
before using it in C programming.
Declaration means announcing the properties of the variable to the
computer and Definition means allocating memory to a variable.The
properties, which are:
Size of the variable
Name of the variable
Most of the time declaration and definition will be done at the same time, but
this depends on the modifier that is mentioned with the variable.
int var;
var = 5;
C KEYWORDS
Keywords are predefined, reserved word whose meaning already defined in
the compiler. There are 32 keywords in C, each keywords has a special
meaning of work and the few of them are:
break: The break keyword terminates the innermost loop immediately when
it’s encountered.
goto: Use to jump to a particular location.
return: Suppose an integer data or a character is needed to be return, then
return keyword can be use
continue: The continue keyword skips the statement after it’s inside the loop
for iteration
switch, case
and default keyword: They used when a block of statements has to be
executed among many blocks
char: The char keyword declares a character variable
const: An identifier can be declared constant by using const keyword
If and else: They are use to make decisions
C OPERATORS
Operators are symbol that tells the compiler to perform a specific
mathematical or logical functions. In C program language, there are built-in
operators and they are:
Arithmetic Operators
Relational Operators
Logical Operators
Assignment Operators
Bitwise Operators
Misc Operators
Operators Meaning
+ Addition
- Subtraction
* Multiplication
/ Divition
% Modulus
++ Increament
-- Decreament
Operators Meaning
== checks equal or not and if yes,
the condition is true.
!= checks if it’s NOT equal
> Greater than
< Less than
>= Greater than equal to
<= Less tham equal to
Assignment Operator:
Operators Meaning
= Simple assignment operator
+= Add AND assignment operator
-= Subtract AND assignment operator
*= Multiply AND assignment operator
/= Divide AND assignment operator
%= Modulus AND assignment operator
<<= Left shift AND assignment operator
>>= Right shift AND assignment operator
&= Bitwise AND Assignment operator
^= Bitwise exclusive OR Assignment
I= Bitwise inclusive OR Assignment
Misc Operators:
Operators Meaning
sizeof Return the size of a variable
& Return the address of a variable
* Pointer to a variable
?: Conditional expression
C CONTROL STRUCTURE
Loop: The statements are executed more than one time. It is also know as
Repetition. They are implemented using While, Do While and For
statements.
Subprogram: Is a program inside a large program that can be reused
multiple times. The main program is suspended during the execution of any
subprogram.
INPUT/OUTPUT
C input, scanf() is commonly used function take input from the user.
The scanf() function reads fprmatted input from the standard input such as
keyboard. Input means to provide the program with some data to be use in
the program.It can be given in form of file of from command line.
C programing language provides a set of built-in functions to read the
input and give it to the program as required.
Output means to dispaly data on the screen or write the data to a printer or
file. C output, printf() is the main output function. The function send formatted
output to the screen, printf() is a library function and it can be use in the
program by including the header file stdio.h using #include <stdio.h>
example:
putchar(): It is
a file handling
function in C programming language which is used to write a character on a
standard out/screen.
Getchar(): it is used to get or read a character from keyboard input.
Example:
To close a file: The fclose(-) function returns zero on success, or EOF( end
of file) if there is an error in closing the file. The function flushes any data still
pending in the buffer to the file, close the file and release any memory used
for the file. The EOF is a constant define in the header file stdio.h
fgets() and fputs() function are examples
fgets() function reads string from a file pointed by file pointer. It also copies
the string to a memory location referred by an array
fputs() function is useful when when a string is to written into an opened file.
Concurrency is the ability to run and manage multiple tasks at the same
time. It is the idea of running and managing several tasks at the same time. C
does not have any library function that handles concurrency, external
functions are used to handle it. Concurrency is core area in computer science
that has existed for a long time in the area of high performance and
scienstific computing. A minimal concurrency systen can be achieved by
creating a coroutines (coroutines are generalized routine which predefine
points where execution is suspended and can be resumed at a leter time)
which instead of context switching among eash other, always ask the
scheduler/oracle where to context switch next. Context switching is a
technigue or method used by OS to switch a process from one state to
another.
REFERENCE
Giraff Academy
Naso Academy
programiz.com
tutorialspoint.com
Docs.microsoft.com
Beginnersbook.coms