Pointer Based Programs in C
Pointer Based Programs in C
Pointer Based Programs in C
Write a c program to display the address of a float and int type variable using pointers
#include <stdio.h>
int main() {
// Declare variables
int integerValue;
float floatValue;
// Display addresses
printf("Address of integer variable: %p\n", intPointer);
printf("Address of float variable: %p\n", floatPointer);
return 0;
}
2. WAP in C to print the contents of an integer array by using Pointers.
#include <stdio.h>
int main() {
ptr++;
ptr--;
return 0;
}
3. Write a c program to show the change of memory address that is observed after incrementing the pointer to an
integer
#include <stdio.h>
int main() {
ptr++;
return 0;
}
4. Write a c program to show the change of memory address that is observed after incrementing & decrementing
the pointer to a float variable.
#include <stdio.h>
int main() {
ptr++;
ptr--;
return 0;
}
5. Write a program to add and subtract 2 integers using pointers
#include <stdio.h>
int main() {
// Declare variables
scanf("%d", &num1);
scanf("%d", &num2);
// Declare pointers
// Display results
return 0;
}
6. Write a program to find the largest and smallest elements of an array using pointers
#include <stdio.h>
int main() {
// Declare variables
int size;
scanf("%d", &size);
if (size <= 0) {
int arr[size];
scanf("%d", &arr[i]);
ptrLargest = &arr[i];
ptrSmallest = &arr[i];
return 0;
7. Write a program to swap the values of 2 integers with and without using pointers
#include <stdio.h>
int main() {
// Declare variables
int num1, num2;
return 0;
}
Using pointers:
#include <stdio.h>
int main() {
// Declare variables
int num1, num2;
return 0;
}
#include <stdio.h>
int main() {
// Declare variables
int value = 42;
int *ptr1 = &value; // Pointer to an integer
int **ptr2 = &ptr1; // Pointer to a pointer to an integer
return 0;
}