You are on page 1of 19

AKINYOTU DAMILOLA VICTOR

DE.2017/4579

Course Code: CMS 411

Course Title: ORGANIZATION OF PRGRAMMING


LANGUAGE

ASSIGNMENT : REVIEW OF C PROGRAMMING


LANGUAGE

given

by

Dr. Benneth

RIVERS STATE UNIVERSITY


Nkpolu-Oroworukwo, port Harcourt, Rivers State, Nigeria.
ABSTRACT

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

 INTRODUCTION TO C PROGRAMMING LANGUAGE


 C PROGRAMMING ENVIRONMENT
 C PROGRAME ENTERING POINT
 C FUNCTIONS
 C COMMENTS
 WHITESPACE
 DELIMETERS
 DATATYPES
 VARIABLES
 C KEYWORDS
 C OPERATORS
 C CONTROL STRUCTURES
◦ SEQUENCE
◦ SELECTION
◦ LOOP
◦ SUB-PROGRAMS
◦ FUNCTIONS
 INPUT/OUTPUT
◦ USER I/O APPROACH
◦ FILE I/O APPROACH
 HOW C HANDLES CONCURRENCY
 REFERENCE

INTRODUCTION TO C PROGRAMMING LANGUAGE


This is written to explain the uniqueness of C programming Language
and why it is referred to as a programming Language.
C programming is a procedural language. It is a set of procedure
functions, it is the description between high level language and low level
language. C programming is neither a high level language or a low level
language which make it a middle level language. C programming can be
called a middle level language because it makes programming simpler for
human beings and also allow us to access different system level features like:
 Direct access to memory through pointer
 Bit manipulation using bitwise operator
 Writting Assembly code withing C code
C is a popular choice for system level applications, it is a coding language
choice for Kernnel development.
Kernnel is the central part of an operating system, it manages the tasks
of the computer and the hardware, cpu time and memeory. It is the most
fundamental part of an operating system, it can be thought of as the program
which controls all other programs on the computer. It is reponsible for creation
and destruction of memory space which allows software to run.
C can be use in variety of fields, including app development, game
programming, compiler development and so on.
Many programming languages have borrowed features directly or
indirectly from the C language, some from programming languages like Java,
PHP, JavaScript, and many other languages are based on the C language.
C++ is is derived from C language( Few programs may compiled in C, but not
in C++. C was designed and written by Dennis Ritchie in the year 1972 in
USA.
ANSI ( America National Standard Institute) commitee developed a
rules ( known as ANSI C) for all version of C. As long as you run programs
using ANSI C compiler, you can be sure that you can compile your C program
on almost any compiler that has an ANSI C compiler. ANSI C standard.
The Structure of C programs starts by including the Header file and
then declaring the main() function, Variable declaration, Body and then the
Return Statement

C PROGRAMMING ENVIRONMENT

In C programming, programming Environment is simply a place where text


can be edited called Text Editor and the C compiler, this brought about IDE
( Integrated Development Environment). It is a place where programs can be
compiled, edited, debug and executed.
Text Editor is used to type your program, examples are Notepad, OS
Edit command, Brief, vim, Epsilon etc.
The C compiler compiles the source codes into an executable programs
or machine language, the source code is the human readable code and
executable program is the language that the computer can understand which
0s and 1s.
There are softwares used as programming environment and they are:
 Visual Studio Code
 Xcode
 Eclipse
 NetBeans
 Arduino IDE
 Particles
 Appcode
 Sublime Text
 Atom
 Code::Blocks
 CodeWarrior
 Dev-C++ , e.t.c
They are all built for the benefit of editing text and executing programs, they
also help to prevent mistakes, organizes resources and provides shortcuts.
IDEs organize imports and can add appropriate imports, it can give a warning
incase of any errors or mistake, they make the unit test’s running easy. The
softwares listed above, C programming language support them.

C PROGRAMMING ENTERING POINT

Programming Entering Point in C programming is a location where a


transfer of program control(execution) occurs. It is a line where execution
starts.
The (main()) function is the entry point to a C program and is called
when a the appliction starts executing. Every C program has a primary (main)
that must be named main. It usually controls program execution by directing
the calls to other functions in the program.
Functions within the source program one or more specific tasks. The
main function can call these functions to perform their respective tasks. When
main calls another function, it passes execution control to the function. The
main funtion can be anywhere in the program but in general practice it is
placed in the first position.

Syntax:

main()

.................
..................
.................

The main() funtion return value when it declared by data type as


int main()
{
............
............
return 0;
}

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

In C programming language there are types of functions and the are:


 Standard Library Functions
 User-define Functions

Standard Library Functions: They are built-in functions in C programming.


These functions are define in the header-file. For example:
 The (printf()) is a standard library function to send output to the screen
(display output on the screen) and so as there is a way to input to the
program using (scanf()). This function is defined in the stdio.h header
file and this can be include in the program using #include <stdio.h>.
 The (sqrt()) function calculates the square root of a number. The
function is defined in the math.h header file using the #include
<math.h> to include it in the program.
There are other standard library fuctions like string.h, stdlib.h, time.h e.t.c
User-define Functions: This are functions created by the user to perform a
specific task.
Syntax:
return_type function_name(argument list)

set of statement-Block of code


}

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.

 In C programming there is no limit on number of functions, a C program


can have any number of functions.
 main() in C program is also a function.
 A function can call it’self, the process is known as Recursion.
 In C return_type, Data type returned value. It can be void also, in that
case no value is returned.
In C the main() is treated the same way other functions are treated, eaxmpe:
User-define Function are generated outside the main function and then later
recalled in the main function, example:

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.

There are two types of comments in C programming languagege and they


are:
 Single line comment (// comment goes here)
 Multiline comment (/* comment goes here */)
Single line comment: Anything written after // in the line is treated as a
comment
Multiline comment: Anything written in between /* and */ is treated as a
comment.
Examples:

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

Primary/Basic/foundamental Data type: They are foundamental data types


in C, and they are:
a) Integer (int)
b) Floating Point (float)
c) Character (char)
d) Void

Integer (int): They are used to store or hold whole numbers.


Size on 16-bit machine:
 int or signed int 2 bytes
 unsigned int 2 bytes
 short int or signed short int 1 byte
 unsigned short int 1 byte
 long int or signed long int 4 bytes
 unsigned long int 4 bytes

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

Character (char): Character type are used to store character values.


Size on 16-bit machine:
 char or signed char 1 byte
 unsigned char 1 byte

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.

Enum(enumerated Data Type): Is a special data type consiting of a set of


name values called elements or members. It is mainly use to assign names to
integral cinstants, which make a program more readable.

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.

Example of variable declaration:


int main()
{
int var; // This case “int” is the data type and “var” is the declared variable.
}

Initialization: This means assining a value to a variable at the time of


declaration and it does’nt mean you can’t change the value.
C have several different kinds of variables because there are several
different kinds of data. Not just any variable will hold just any piece of data.
Only floating point variables can hold floating point data, and so on. In c
programming variable vary in size , depending on the kind of data they will
hold, and each variable has a unique name that defferentiate it from other
variables.
C is one of the few programming language that has no string variables.

Variable Naming Rules in C:


 All variable name must be didfferent, you can’t have two variables in the
same program with the same name
 A variable can have from 1 to 31 character in it’s name. Some compiler
do allow longer names
 Your program’s variable must begin with a letter of the alphabet, but
after that letter, variable names can have other letters, number, or an
unserscore in any combination. All of the following are valid variable
names:
myData pay94 age_limit amount.
 C let you begin a variable name with underscore, but you should’nt do
so, some of C’s built-in variable begin with an underscore, so there is a
chance you’ll overlap one of those if you name your variable starting
with underscore
 Don’t name a variable with the same name as a function or a command,
program won’t and if tried to use that function later in your program, it
will cause an error.
Most C variable are defined after an opening brace that follow afuntion
name. These variables are called Local variables.
C also let you create Global variables by defining the variables before
main()
In C, you can assign value to a variable using the equal sign (=). like
this:

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

Arithemetic Operators: They are popular operators and they are:

Operators Meaning
+ Addition
- Subtraction
* Multiplication
/ Divition
% Modulus
++ Increament
-- Decreament

Relational Operators: They are,

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

This a statement that use to control the flow of execution in a program.


It combines instruction in a logical unit. Logical uint has one entry point and
one exist point.

Types of Control Structure in C language:


 Sequence
 Selection
 Loop
 Sub-program
 Function
Sequence: Statements are executed in a specified order. No statement is
skipped and no statement is executed more than once(straight line paths)
and it is the default control structure.
Example:
Selection: It select a statement to execute on the basis of condition.
Statement is executed when the condition is true and ignore when it is
false(one or many branches). They are implemented using if , if Else and
Switch statements.

Function: It is used to invite or call a piece of code to statement. In this case


control jumps from main program to that piece of code and the returns back
to main program.

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:

gets() and put() function


Both functions are used in the input and output operation of the strings. The
gets() functions are used to read string input from the keyboard and the puts()
function displays it. The function are also declared in the std.h header file.

File o/i Approach


C programming language provides access on high level functions as
well as low level (os level) calls to handle file on storage devices.

To open a file: fopen() function is used to create a new file or to open an


exiting file.
The format is : FILE * fopen ( const char * filename, const char * mode );
filename: Is a string literal, which is use to name the file
mode: It can be r, w, a, r+, w+, a+
 (r): It is use to open an existing text file for reading purpose
 (w): It is use to open a text file for writting. If it does not exist, then a
new file is created
 (a): It is use to open a text file for writting in appending mode, if it does
not exist, then a new file is created
 (r+): It is use to open a text file for both reading and writting
 (w+): It is use to open a text file for both reading and writting . It first
shorten the file to zero length if it exists otherwise create a file if it does
not exist
 (a+): It is use to open a text file for both reading and writting. It creates
the file if it does not exist. The reading will start from the beginning but
writting can only be appended.

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.

HOW C HANDLES CONCURRENCY

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

You might also like