This commit is contained in:
2025-09-19 16:32:47 +03:00
parent e1b9f50edc
commit a92349ee38
12 changed files with 374 additions and 2 deletions

View File

@@ -0,0 +1,19 @@
#include <stdio.h>
int main(void) {
int m = 10;
int *z = &m;
int n, o;
printf("\n\n Pointer : Show the basic declaration of pointer :\n");
printf("-------------------------------------------------------\n");
printf(" Here is m=10, n and o are two integer variable and *z is an integer");
printf("\n\n z stores the address of m = %p\n", z); // Printing the address stored in z using %p
printf("\n *z stores the value of m = %i\n", *z); // Printing the value pointed to by z using *z
printf("\n &m is the address of m = %p\n", &m); // Printing the address of m using &m
printf("\n &n stores the address of n = %p\n", &n); // Printing the address of n using &n
printf("\n &o stores the address of o = %p\n", &o); // Printing the address of o using &o
printf("\n &z stores the address of z = %p\n\n", &z); // Printing the address of z using &z
return 0;
}

View File

@@ -0,0 +1,13 @@
#include <stdio.h>
int main(void) {
int m = 29;
int *ab = &m;
printf("m: %d, *ab: %d, ab: %d, address m: %d\n", m, *ab, ab, &m);
m = 32;
printf("m: %d, *ab: %d, ab: %d, address m: %d\n", m, *ab, ab, &m);
*ab = 7;
printf("m: %d, *ab: %d, ab: %d, address m: %d\n", m, *ab, ab, &m);
return 0;
}

View File

@@ -0,0 +1,19 @@
#include <stdio.h>
int main(void) {
int m = 300;
float fx = 300.600006;
char cht = 'z';
int *p1 = &m;
float *p2 = &fx;
char *p3 = &cht;
printf("The & operator: m=%p, fx=%p, cht=%p\n", &m, &fx, &cht);
printf("The & and * operator: m=%d, fx=%f, cht=%c\n", *(&m), *(&fx), *(&cht));
printf("Using only pointer variable: m=%p, fx=%p, cht=%p\n", p1, p2, p3);
printf("Using only pointer operator: m=%d, fx=%f, cht=%c\n", *p1, *p2, *p3);
return 0;
}

View File

@@ -0,0 +1,14 @@
#include <stdio.h>
int main(void) {
puts("Num adder with pointer!");
int num1, num2;
int *p1 = &num1;
int *p2 = &num2;
puts("Enter p1 and p2!");
scanf("%d", &num1);
scanf("%d", &num2);
printf("Total:%d\n", (*p1) + (*p2));
return 0;
}

View File

@@ -0,0 +1,24 @@
#include <stdio.h>
void sumOfNums(int *num1, int *num2);
int main(void)
{
int num1, num2;
puts("Enter num1 and num2");
scanf("%d %d", &num1, &num2);
int *p1 = &num1;
int *p2 = &num2;
sumOfNums(p1, p2);
return 0;
}
void sumOfNums(int *num1, int *num2) {
printf("Sum of Nums: %d\n", (*num1) + (*num2));
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
int main(void)
{
int num1, num2;
int *p1 = &num1;
int *p2 = &num2;
puts("Enter nums!");
scanf("%d %d", p1, p2);
(*p1 > *p2) ? printf("%d > %d", *p1, *p2) : printf("%d <= %d", *p1, *p2);
return 0;
}

View File

@@ -0,0 +1,21 @@
#include <stdio.h>
int main(void)
{
puts("Input the number of elements to store in the array: ");
int arr = 0;
scanf("%d", &arr);
int nums[arr] = {};
for(size_t j = 0; j < arr; j++) {
printf("For Element %d enter num!\n", j);
int num = 0;
scanf("%d", &num);
nums[j] = num;
}
for(size_t j = 0; j < arr; j++) {
printf("Element %d = %d\n", j, nums[j]);
}
return 0;
}