Computer_Assignment_Solutions
Computer_Assignment_Solutions
1. What is function?
A function is a block of code that performs a specific task. It can take inputs (parameters), process
Functions are used to improve modularity and reusability in programming. They allow breaking down
Function declaration informs the compiler about the function name, return type, and parameters
Prototype refers to the same declaration, ensuring consistency in function calls and definitions.
Passing by reference means passing the memory address of variables to a function, allowing the
Example:
```c
*x = *y;
*y = temp;
int main() {
int a = 5, b = 10;
swap(&a, &b);
printf("a = %d, b = %d", a, b);
return 0;
```
5. What is pointer?
```c
int a = 5;
```
```c
*x = *y;
*y = temp;
```
Recursion is a programming technique where a function calls itself to solve a smaller instance of the
- Recursion is a function calling itself, while iteration involves loops like for or while.
- Recursion uses more memory (stack) compared to iteration.
An array is a collection of elements (of the same data type) stored at contiguous memory locations.
- Array initialization assigns values during declaration, e.g., `int arr[3] = {1, 2, 3};`.
- Bound checking ensures the array index is within the valid range. C/C++ does not perform
```c
printf("%d", elem);
int main() {
printElement(arr[0]);
```
Example:
```c
int *p = arr;
for (int i = 0; i < 3; i++) {
```
```c
int arr[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
printf("\n");
```