Module 3
Module 3
Pointers
**Code:**
```c
#include <stdio.h>
int main() {
int a = 10;
return 0;
```
**Output:**
```
Value of a: 10
```
```c
#include <stdio.h>
int main() {
return 0;
```
**Output:**
```
First Element: 10
Second Element: 20
```
**Code:**
```c
#include <stdio.h>
int main() {
return 0;
```
**Output:**
```
Value: 10
Value: 20
Value: 30
```
### 2. Functions
**Code:**
```c
#include <stdio.h>
void add(int x) {
x++;
int main() {
int a = 5;
return 0;
```
**Output:**
```
Inside add: 6
In main: 5
```
**Code:**
```c
#include <stdio.h>
(*x)++;
int main() {
int a = 5;
return 0;
}
```
**Output:**
```
Inside add: 6
In main: 6
```
**Code:**
```c
#include <stdio.h>
return x + y;
int main() {
return 0;
```
**Output:**
```
Sum: 15
```
#### Recursion
**Code:**
```c
#include <stdio.h>
int factorial(int n) {
int main() {
return 0;
```
**Output:**
```
Factorial of 5: 120
```
### 3. Structures
**Code:**
```c
#include <stdio.h>
struct Point {
int x;
int y;
};
int main() {
p1.x = 5;
p1.y = 10;
return 0;
```
**Output:**
```
```
**Code:**
```c
#include <stdio.h>
struct Student {
char name[50];
int id;
};
int main() {
return 0;
```
**Output:**
```
```
**Code:**
```c
#include <stdio.h>
struct Point {
int x;
int y;
};
int main() {
return 0;
```
**Output:**
```
```
### 4. Unions
**Code:**
```c
#include <stdio.h>
union Data {
int i;
float f;
char c;
};
int main() {
data.i = 10;
data.f = 5.5;
return 0;
```
**Output:**
```
data.i: 10
data.f: 5.500000
```
### 5. Enumerations
**Code:**
```c
#include <stdio.h>
int main() {
dir = North;
return 0;
```
**Output:**
```
Direction: 0
```
### 6. typedef
**Code:**
```c
#include <stdio.h>
int main() {
return 0;
```
**Output:**
```
Number: 5000
```
**Code:**
```c
#include <stdio.h>
int main() {
FILE *fp;
if (fp == NULL) {
return -1;
return 0;
```
**Output:**
(No output on the console, but a file named `test.txt` will be created with the content.)
```plaintext
Hello, World!
```
**Code:**
```c
#include <stdio.h>
int main() {
FILE *fp;
char buffer[100];
// Writing to a file
fp = fopen("test.txt", "w");
fclose(fp);
fp = fopen("test.txt", "r");
fclose(fp);
return 0;
```
**Output:**
```
```