Skip to content

Commit 92d102b

Browse files
authored
Pointer Programs
1 parent ebca600 commit 92d102b

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

Pointer_Arithmetic.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stdio.h>
2+
#include <conio.h>
3+
int main() {
4+
5+
int a, b, *p, *q, sum;
6+
printf("Enter the Values of the two numbers :: ");
7+
scanf_s("%d %d", &a, &b);
8+
p = &a;
9+
q = &b;
10+
sum = *p + *q;
11+
12+
printf("\nThe Sum of the two Numbers using Pointer is : %d", sum);
13+
_getch();
14+
return 0;
15+
}

Pointer_Array.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include<stdio.h>
2+
#include<conio.h>
3+
int largest(int *, int);
4+
void main()
5+
{
6+
int i, no_terms, a[10];
7+
printf("Enter the Number of Elements of the Array :: ");
8+
scanf_s("%d", &no_terms);
9+
printf("\nEnter the Elements of the Array :: ");
10+
for (i = 0; i < no_terms; i++)
11+
scanf_s("%d", &a[i]);
12+
13+
printf("\nThe Largest Element of the Array is :: %d ", largest(a, no_terms));
14+
_getch();
15+
}
16+
int largest(int *g, int n)
17+
{
18+
int max = *g, i;
19+
for (i = 1; i < n; i++)
20+
if (*(g + i) > max)
21+
max = *(g + i);
22+
return max;
23+
}

Pointer_Basics.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
#include <conio.h>
3+
int main() {
4+
5+
int var1, var2[10];
6+
int *q, *w;
7+
q = &var1;
8+
w = var2;
9+
printf("Address of var1 variable: %x\n", &var1);
10+
printf("Address of var2 variable: %x\n", &var2);
11+
12+
printf("Address of var1 variable using Pointer is : %p\n", q);
13+
printf("Address of var2 variable using Pointer is : %p\n", w);
14+
_getch();
15+
return 0;
16+
}

0 commit comments

Comments
 (0)