Anda di halaman 1dari 7

Computer Fundamentals Notes

By: Nida Afaq Warsi

BEE-3B
Variables

Variables are references that stand in for a value that is contained at a certain memory address.
Variables are said to have a value and may have a data type.

Example:

Variable X

Each cell in the above diagram represents a memory location, and can be excessed through a
Each cell represents a unit of memory called a byte. Each byte consists of 8 bits.
Eight bits is a convenient power of two allowing the values 0 through 255 to be stored on one
8
byte.(As 2 = 256, thus including 0 a total of 255 values can be stored)

To store a value greater than 255, we combine two cells and treat them as a single number.
Each cell can now store 255 values each thus a maximum value of 232-1 = 65535 can be stored
using two bytes.

Example:

Z
X

Y
8

Z= 2 Y +X

The order in which this sequence of bytes is stored is called Little Endian. In this order the "little
end" or the least significant value in the sequence is stored first. Thus X being the least
significant is stored before Y.

Example:
To store the number Z = 1000 the value of X= 232 while Y = 3.

The table below shows some of the values of X and Y with the corresponding value of Z.

255

255

256

257

255

511

255

255

65535

Variable
Name

Example X,Y

Data Type

Size

Depends on the data type

Example integer value maybe 32 bits
Actual Content

Value

*Note: Left hand side should have only variables.

Example:
Correct Expression:
Z=X+4
Incorrect Expression:

X+4=Y+7

Expressing The Quadratic Formula in terms of the basic functions

Sum (a,b) = a+b
Product (a,b) = ab
Sqrt (a) =a
Div (a/b) = a/b

Root(a,b,c) = -b +b2-4ac
2a
Div(Sum(Sqrt(Sum(Prod(b,b),(Prod(Prod(a,c),-4))))),Prod(b,-1))Prod(2,a)
Start from the center, in the above example from the product of a and c and

Creating a function add with two input parameters and an output

parameter
+:

x
The above symbols mean mapping from two sets of real number to one set.
Function add is written in the beginning.
Symbol Indicates that the two parameters to be added are real
numbers, and the resultant value is also a real number.

+:

The above symbolic representation indicates that two integers add to give
another integer.

Naming the function

In C programming the function name has to start with a letter. Numbers
can than follow.
Example: doc, A2,a23b, abc
The letters maybe in uppercase or lowercase (Note C language is case
sensitive)
There should not be any punctuation or spaces in the name of the function.
Underscore can be used in the name if the function.
Example:
+:

x
Data Types
Character (char)

8 bit integer value

Integer (int)
Long

16 0r 32 bit integer
value
32 bit integer value

Float

Simple

Double

More precise

Float and double are use to store real numbers.

Modifiers
A type modifier alters the meaning of the base type to yield a new
type.
Two modifiers: 1) Signed 2)Unsigned values.

Signed and unsigned values

We represent a number's sign by allocating one sign bit to represent
the sign: set that bit (often the most significant bit) to 0 for a positive
number, and set to 1 for a negative number.

The remaining bits in the number indicate the magnitude (or

absolute value). Hence in a byte with only 7 bits (apart from the sign
bit), the magnitude can range from 0000000 (0) to 1111111 (127).
Thus you can represent numbers from 127 to +127 once you add
the sign bit (the eighth bit).
A consequence of this representation is that there are two ways to
represent zero, 00000000 (0) and 10000000 (0)
Character
I character has 8 bits thus occupies one cell of memory.
Characters may also be signed or unsigned.
Unsigned characters have values between 0 and 255, signed
characters have values from 128 to 127.
Integer
Considering a 16 bit integer a maximum intrager value is 65535.
A signed integer use one bit for storing sign and rest 15 bits for
number. Its value range limited to -32768 to +32767.
Long
It is a 32- bit value
Float
The float data type is used to store fractional numbers (real
numbers) with 6 digits of precision.
Float is faster than double.
Double
The double is same as float but with longer precision and takes
double space (8 bytes) than float.
Double consumes more memory than float.

Analysing the Program

Program 1
#include <stdio.h>
int main(void)
{
printf (Hello, world!\n);
return 0;
}

A function in C language is a block of code that performs a specific task.

Every function has a unique name. This name is used to call function from
main() function.
A function is independent and it can perform its task without intervention
from or interfering with other parts of the program.
must perform as a part of its overall operation, such as adding two or more
integer.
A function returns a value to the calling program. This is optional and
depends upon the task your function is going to accomplish. Suppose we
want to just show few lines through function then it is not necessary to
return a value.
But if you are calculating the sum of two numbers and wanted to use result
somewhere in program then you have to send back (return) value to the
calling function.

C language is collection of various inbuilt functions. If you have written a

program in C then it is evident that you have used Cs inbuilt functions.
Printf, scanf, clrscr etc. all are Cs inbuilt functions.
There are no parameters of the above function as it says (void).
The return type of this function is an integer since it says:
int main (void)
The text enclosed in quotation marks is called string.
\n means new line
Prototypes are often in a separate header file which can be included in other
C source files that wish to use the functions. The header stdio.h, for
example, contains prototypes for the functions scanf and printf. The
compiler will let us call those functions. The actual code for these functions
is kept in a library elsewhere on the system, the header file only says how to
interface with the functions.

return 0;