Pointer
Pointer
1 Problem Statement :
Write a program to swap two integers using pointers.*/
#include <stdio.h>
// Function to swap two integers using pointers
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int x, y;
// Input two integers
printf("Enter the first integer: ");
scanf("%d", &x);
printf("Enter the second integer: ");
scanf("%d", &y);
// Display original values
printf("\nBefore swapping:\n");
printf("x = %d, y = %d\n", x, y);
// Call the swap function
swap(&x, &y);
// Display swapped values
printf("\nAfter swapping:\n");
printf("x = %d, y = %d\n", x, y);
return 0;
}
//OUTPUT
Before swapping:
x = 5, y = 9
After swapping:
x = 9, y = 5
#include <stdio.h>
int stringLength(const char *str) {
const char *ptr = str; // Pointer to the start of the string
int length = 0;
return length;
}
int main() {
char str[100];
// Input the string
printf("Enter a string: ");
scanf("%99[^\n]", str); // Read input with spaces
//OUTPUT