Pointer
Pointer
Pointer
Pointer to an Integer
c
Copy code
#include <stdio.h>
int main() {
int num = 10;
int *ptr = #
return 0;
}
2. Pointer to a Float
c
Copy code
#include <stdio.h>
int main() {
float num = 5.67;
float *ptr = #
return 0;
}
3. Pointer Arithmetic
c
Copy code
#include <stdio.h>
int main() {
int arr[3] = {1, 2, 3};
int *ptr = arr;
return 0;
}
4. Pointer to a Character
c
Copy code
#include <stdio.h>
int main() {
char ch = 'A';
char *ptr = &ch;
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
int x = 5, y = 10;
swap(&x, &y);
return 0;
}
6. Pointer to an Array
c
Copy code
#include <stdio.h>
int main() {
int arr[3] = {10, 20, 30};
int *ptr = arr;
return 0;
}
7. Pointer to a Pointer
c
Copy code
#include <stdio.h>
int main() {
int num = 100;
int *ptr = #
int **pptr = &ptr;
return 0;
}
c
Copy code
#include <stdio.h>
int main() {
int x = 10;
addOne(&x);
return 0;
}
9. Pointer to a Structure
c
Copy code
#include <stdio.h>
typedef struct {
int id;
char name[50];
} Student;
int main() {
Student s1 = {1, "John"};
Student *ptr = &s1;
return 0;
}
10. Dynamic Memory Allocation
c
Copy code
#include <stdio.h>
#include <stdlib.h>
int main() {
int *arr = (int *)malloc(3 * sizeof(int));
if (arr == NULL) {
printf("Memory allocation failed\n");
return 1;
}
free(arr);
return 0;
}