0% found this document useful (0 votes)
6 views

assignment(1)_Advanced_c_

Uploaded by

hadeerrady2003
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

assignment(1)_Advanced_c_

Uploaded by

hadeerrady2003
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

NAME: Hadeer rady abd elzaher

TRACK: SOFT WARE


SEC:4
Task No.01

1- Explain the meaning of function recursion in C language


 Function recursion is a technique in programming where a function
calls itself directly or indirectly.

 Recursive Function: A function that calls itself directly or


indirectly.
 Base Case: The condition that stops the recursion.

 Recursive Case: involves function calling itself with modified


arguments

2- Create a program to print the above triangle pattern in


Figure 1 using function recursion

3- Distinguish the type of calling of function you use in


creating the pattern.

 This program uses tail recursion


4- Compare between call by value and call by reference
 Call by Value

Mechanism: A copy of the argument's value is passed to the


function.
Impact: Changes made to the argument within the function do not
affect the original value outside the function.
Efficiency: Generally more efficient due to the overhead of
copying arguments.

 Call by Reference

Mechanism: The address of the argument is passed to the


function.
Impact: Changes made to the argument within the function
directly affect the original value outside the function.
Efficiency: Less efficient due to the overhead of passing
pointers

5- Create a full program for the first semester academic


calendar using the C language.
6- Use pointer to write a program that find the number of '*'
in the above pattern
Task No.02
7- Explain the data types that will be used to hold customer
information so that the customer dashboard will be

 Data Types for Customer Information in a C Program:


 Essential Data Types:
1) Customer ID: int or long int (for unique numeric
identification)
2) Customer Name: char array (for storing text strings)
3) Customer Address: char array (for storing text addresses)
4) Contact Information (Phone, Email): char array (for storing
text strings)
5) Payment Information: char array (for storing text strings)
6) Other Relevant Data (Purchase History, Preferences): char
array or custom structures (depending on complexity)

 Data Structure:
struct Customer {
int customerID;
char name[50];
char address[100];
char phone[20];
char email[50];
char paymentInfo[100];
};
8- Create a C functions to Add new record and view payment using
the output of the following figures
9- Identify the functions that are used to dynamically allocate memory
location during runtime and the function of the following string
functions
- strcpy
- strcmp
- strlwr
- strlen
 Dynamic memory allocation in C:
1: The malloc() function allocates single block of requested memory.
• memory allocation
• It doesn't initialize memory at execution time,so it has
garbage value initially.
• It returns NULL if memory is not sufficient.
 The syntax of malloc() function is
ptr=(cast-type*)malloc(byte-size)
__________________________
2: calloc() function is used to dynamically allocate multiple blocks of
memory.
• calloc() needs two arguments instead of just one
void *calloc(size_t n, size_t size)
 first argument is the number of blocks
 second argument is the size of each block
• Memory allocated to calloc is initialized to zero but malloc
is initialized with some garbage value
______________________________

3:Realloc(): If memory is not sufficient for malloc() or calloc(),


you can reallocate the memory by realloc() function. realloc()
function is used to change the

 size of the memory block without losing the old data.


void *realloc(void *ptr, size_t newSize)
 First term pointer to the previously allocated memory
Second term is the new size.
 On failure realloc returns NULL
______________________________
4:free(): function is used to release the dynamically allocated
memory
void free(ptr);
 The memory allocated in heap will not be released automatically
after using the
 memory. The space remains there and can’t be used.
__________________________________
 string functions :
- strcpy:The strcpy(destination, source) function copies the source
string in destination.
- strcmp: The strcmp(first_string, second_string) function compares
two string and returns 0 if both strings are equal.
- strlwr:The strlwr(string) function returns string characters in
lowercase.
- strlen:The strlen() function in C calculates the length of a
given string.
• The strlen() function is defined in string.h header file. It
doesn’t count the null character ‘\0’.

10- Write the full C program to implement the university staff billing
system.

11- Also write a program in C to print individual characters of a string


(name)

You might also like