Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Aydid Mohamed Ahmed

1693108
BSIT
CC103

Research on the following topics:


Use books from the library (include proofs that you used books).

1. Difference between Type Conversion and typecasting (give


example program)
2. What is a Function?
a. Why do we need a function?
b. Function definition and function call
C. sample program that uses function
3. What are a Pointer and its applications?
a. Sample program that uses functions

Answers:

Differences between Type Casting and Conversion:

1. The basic difference which distinguishes type casting from type conversion is
that type casting is conversion of one type to another, done by the programmer
On the other hand, the type conversion is conversion of one type to another,
done by the compiler while compiling.
Type casting can be applied to the data types which may not be compatible with
each other but, type conversion can only be applied to the data types which are
compatible with each other. The conversion of one type to another in type casting
requires the casting operator “( )” while, the conversion of one data type to
another in type conversion do not require any operator. While converting one
data type to another in type casting, the destination type can be larger or smaller
than the source type. On the other hand, the destination type must be larger than
the source type in type conversion. The conversion of one type to another type is
done while coding in type casting whereas, in type conversion, the conversion of
one type to another is done explicitly during compilation. Type casting is called
narrowing conversion because here the destination type can be smaller than
source type whereas, type conversion is called widening conversion because
here, the destination type must be larger than the source type.

https://techdifferences.com/difference-between-type-casting-and-type-
conversion.hltm

A; EXAMPLE TYPECASTING:

Int a;
byte b;
...
...
b= (byte) a;

EXAMPLE TYPECONVERSION

int a=3;
float b;
b=a; // value in b=3.000.

2. A function is a specialized subprogram that does nothing but calculate and


Return a single value. If you want to calculate the cube of a number (which is
The same number multiplied by itself three times
A: Function declaration and.definition is the area where the ANSI standard has
Made the most visible changes to C.

B: Function definition: Rather than type similar instructions


multiple times (using slightly different
Numbers), you can store instructions in a function. Then you pass data to the
Function, and the function spits back a single value. A function consists of
The following four parts:
_ A name
_ One or more instructions for the function to calculate a single value
_ One line that assigns a value (or an expression that represents a value)
To the function name
_ Any data that you want the function to use

Function call: Of course, you want to use the function that you create in
your program. A
Function represents a single value, such as an integer or a double-precision
Number, so you can treat the function name as a variable.

C: sample program that uses function

PROMPT “Type a number:”; my number


NOTICE “This is the cube = “; Cube (my number)
END
FUNCTION Cube (Number)
Cube = Number * Number * Number
END FUNCTION

3: A pointer is a variable that contains the address of a variable


Consider the problem of writing a function month name (n), which returns
a pointer to a character string containing the name of the n-the month. This is
An ideal application for an internal static array.
A: Sample program that uses functions
the proofs that I used books

You might also like