0% found this document useful (0 votes)
70 views17 pages

CSC202A Assignment 1 (Complete)

The document discusses the C programming language. It defines tokens in C as the basic building blocks used to develop C programs, consisting of keywords, identifiers, strings, operators, constants, and special symbols. It also provides examples of preprocessor directives like #define that allow macros to be defined and code to be replaced.

Uploaded by

Jia Xin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views17 pages

CSC202A Assignment 1 (Complete)

The document discusses the C programming language. It defines tokens in C as the basic building blocks used to develop C programs, consisting of keywords, identifiers, strings, operators, constants, and special symbols. It also provides examples of preprocessor directives like #define that allow macros to be defined and code to be replaced.

Uploaded by

Jia Xin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Students Name: Lim Jia Xin

Matric No: J19031189

Task 1

What is Unix Operating System?

Unix is an Operating System that is genuinely the foundation of all Operating Systems such as
POSIX. It was created in the late 1960s by Ken Thompson, Dennis Ritchie, and others in the
AT&T Laboratories.

Unix deals with how the computer works by driving the processor, memory, circle drives,
consoles, video screens, and by performing helpful tasks for the users. Unix Operating System is
intended for multiple users. That is multiple users may have numerous undertakings running
concurrently. It also has a graphical user interface (GUI) like Microsoft Windows which
provides an easily operated environment.

Unix programs are planned around some core philosophies of reasoning that incorporate
necessities such as single-purpose, interoperable, and working with a normalized text interface.
Unix systems are worked around a core kernel that administers the system and other processes.

Kernel subsystems may incorporate process management, file management, memory


management, network management, and others (Help, 2021).

Features of Unix Operating System

1. Multi-user and Time-sharing

Unix Operating System is a multi-user and time-sharing system. It can handle different users
simultaneously. Based on time-sharing, the Unix Operating System can carry out commands
given by different users.

2. Multitasking
The multitasking feature of Unix allows more than one program can be run at the same time. The
fundamental of performing various tasks is maximizing the use of CPU resources. This also
allows users to carry out different tasks at a time.

3. Modularity

Modularity is a significant feature of the Unix Operating System. Unix is comprised of plenty of
modules. Therefore, users can add as well as delete models according to their necessities.

4. Hierarchical File Structure

Unix Operating System uses a hierarchical file structure. This structure first consists of the root
directory and can contain multiple documents or files. Furthermore, hierarchical file structure
allows simple maintenance and skilled execution and has the greatest flexibility in gathering data
in a way that mirrors its regular state. There is no limitation on the number and size of files in
Unix.

5. Powerful Security

Unix Operating System has a powerful security element. People can utilize the system just when
they have the right of access to the users or files. Unix Operating System serves security to
different levels. The profiles of different users and their passwords are protected by external
security. File and directory permissions need to be set under internal security.

6. Portability

Unix Operating System is a portable operating system. It is written in a high-level language to


make it simpler to peruse, understand and change. When it moves to other machines, the code
can be compiled or changed easily on another machine. This means that it can work on machines
of various internal structures. Therefore, clients can choose from a variety of hardware vendors
without being bound by a specific vendor.
7. Utilities and Development Tools

Unix Operating System has over 200 utility programs for different functions. Thus, by joining
existing utilities, new utilities can be constructed easily. Because of that, it can easily complete
tasks such as text processing, sorting, and searching (Chaurasiya, 2020).

Task 2

Five of the most important features of the C language

1. Structured Language

Modularity is the concept of storing C programming language code as libraries for additional
future uses. The majority of the C programming language’s powers are mastered by its library,
while the C programming language itself does very little only. Furthermore, the C language has
its library to resolve regular issues such as we can utilize specific functions through header files
stored in the library. Furthermore, modularity also is the concept of designing applications in
subroutines in a process-oriented approach which means that code can be broken in the
subprogram.

For instance,

#include <stdio.h>

void sum()

void sub()


}

2. Simple and Efficient

First of all, the C programming language is simple. This is because the C language can be written
in simple English language so that it is easy for general programmers to understand and develop.
Also, in secondary schools or universities, the C language is usually taught as an introductory
programming language. Over the long haul, it is undeniably true that it is easier to learn any
other programming language if you are familiar with the C language.

3. Case Sensitive

C programming language is case sensitive which means that the C language handles lowercase
and uppercase letters separately. For example, if we declare an integer variable ‘g’ and we enter
‘G’ instead of ‘g’, it will mean a completely different meaning.

4. Portability

C programming language has great portability. This is because, without any changes or slight
changes, programs are written in C language can be run and compile on any system. To
illustrate, the. C file in C language contains source code and can be edited. However, the .exe file
contains the application and can be executed only. When any C program is written and compiled
on a Windows operating system, the program can easily run on other window-based systems.
When the .exe file is copied to any computer that contains the Windows operating system, it will
work appropriately, in light of the fact that the native code of the application is the same as the
operating system. However, this .exe file cannot be executed on other operating systems.

5. Compiler-Based

C programming language is a compiler-based language. It is much faster than other interpreter-


based programming languages such as Java or Python. The compiler treats the entire program as
input, thereby generating an output file with object code. On the contrary, the interpreter takes
one instruction as input and generates output with no files (prashanshasharma, 2021).

Task 3

The C programming data type is a name or a label, which is used to define the data type for
storage or operation. Here is all the primary data types syntax:

1. int

Integers are whole numbers that can have both zeroes, positive and negative qualities however
no decimal qualities. The size of ‘int’ is generally 4 bytes (32 bits). Int is used to declare an
integer variable. Declaring multiple variables at once is allowed.

2. float

Real numbers are stored by ‘float’. The size of ‘float’ is 4 bytes.

3. double

The keyword ‘double’ is similar to ‘float’ as both of them are used to hold real numbers.
However, the difference is the size of ‘double’ is 8 bytes whereas the size of ‘float’ is 4 bytes.

4. char

Character type variables can be declared by using the keyword ‘char’ and the size of ‘char’ is 1
byte.

5. void
‘void’ is a null data type. It has no value. ‘void’ is used in the functions that won’t return any
value to the calling function.

6. short and long

‘short’ and ‘long’ are type specifiers. The size of ‘short’ is 2 bytes and the size of ‘long’ is 4
bytes.

The variables a and b can store integers whereas the variable c can store floating-point numbers.

7. signed and unsigned

‘signed’ and ‘unsigned’ are type modifiers in the C programming language. They are used to
change the data storage of the data.

Variable Definition in C Programming Language

The variable definition determines a data type and contains a rundown of at least one variable of
that type.

‘type’ should be a substantial C data type. Valid C data type includes ‘char’, ‘int’, ‘float’,
‘double’, and any user-defined objects. However, the ‘variable_list’ should comprise at least one
identifier name and be separated by commas.
For example, the line ‘double e, f, g’ orders the compiler to create variables of type ‘double’
named e, f, and g.

In addition, we can assign initial values for the variables in their declaration.

Variable Declaration in C Programming Language

The variable declaration provides the compiler with a guarantee that the variable has a given
name and type for the compiler to continue with further compilation and not necessarily to
request the complete details regarding the variable. Variable definitions are important only at
compile time. When connecting the program, the compiler needs the actual variable definition.

Variable declarations are very helpful especially while using multiple files and defining variables
in one of the files which will be accessible when connecting the program. The keyword ‘extern’
is used to declare variables everywhere. In a C program, although a variable can be declared
many times, it can only be defined just a single time in a file, function, or block of code.
Task 4

The token in the C programming language is the main idea utilized in fostering a C program.
Assume that even we have plenty of words, without joining them, we can’t make a complete
sentence. Similarly, we must use tokens in the C language to develop applications. Thus, we can
say that the token in the C language is the cornerstone of the C programming language. C
language supports 6 types of tokens which are keywords, identifiers, strings, operators,
constants, and special symbols (ashutoshjoshi, 2021).

Here are some examples:

Code:

Keywords
Output:

Code:
Switch

Output:
Code:

Conditional Operators

Output:
In C language, the C preprocessor is a macro processor. The C compiler will automatically use it
to convert the program before the actual compilation (execute the preprocessor instructions
before compilation). C preprocessor allows the program to define macros, so it is called a macro
processor. A macro is a piece of code replaced by the value of a macro. It is defined by the
#define directive.

Here is a list of preprocessor directives and some examples given:

#define example

Code:

Output:
#undef example

Code:

Output:

Compilation time error. This is because ‘PI’ was not declared in this scope.

#if, #else, #endif example

Code:
Output:

Task 5

short int si = 10;

int i = 25;

long int li = 50;

float f = 0.5;

double d = 1.5;

float x1=f + si * i - li;


/*

x1 = 0.5 + 10 * 25 – 50 ( do the multiplication first)

x1 = 0.5 + 250 – 50

x1 = 250.5 – 50

x1 = 200.500000 (Data type is float)

*/

float x2=i / f + si * d;

/*

x2 = 25 / 0.5 + 10 * 1.5 (do the division and multiplication)

x2 = 50 + 15

x2 = 65.000000 (Data type is float)

*/

float x3=(double) i / si * f;

/*

x3 = 25.00 / 10 * 0.5

x3 = 2.5 * 0.5

x3 = 1.250000 (Data type is float)

*/

float x4=li / i + (int) d / f;

/*
x4 = 50 / 25 + 1 (because of the (int)) / 0.5 (do division first)

x4 = 2 + 2

x4 = 4.000000 (Data type is float)

*/
References
ashutoshjoshi. (2021, February 10). C/C++ Tokens. Retrieved from GeeksforGeeks:
https://www.geeksforgeeks.org/cc-tokens/

Chaurasiya, A. (2020, November 05). Read Some Features of Unix Operating System. Retrieved from
learn4seo: https://learn4seo.com/features-of-unix-operating-system/

Help, S. T. (2021, May 30). What Is Unix: A Brief Introduction To Unix. Retrieved from Software Testing
Help: https://www.softwaretestinghelp.com/unix-introduction/

prashanshasharma. (2021, June 08). Features of C Programming Language. Retrieved from


GeeksforGeeks:
https://www.geeksforgeeks.org/features-of-c-programming-language/#:~:text=It%20was
%20mainly%20developed%20as,operating%20system%20or%20compiler%20development.

You might also like