0% found this document useful (0 votes)
7 views1 page

C Program for Stack Element Addresses

The document contains a C program that implements a simple stack using an array. It prompts the user to enter five elements, stores them in the stack, and then prints each element along with its memory address. The program uses pointers to manage the stack operations.

Uploaded by

Akash Verma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

C Program for Stack Element Addresses

The document contains a C program that implements a simple stack using an array. It prompts the user to enter five elements, stores them in the stack, and then prints each element along with its memory address. The program uses pointers to manage the stack operations.

Uploaded by

Akash Verma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

1 #include <stdio.h>
2 #include <conio.h>
3
4 void main() {
5 int stack[5], i;
6 int *top;
7 top = stack;
8 clrscr();
9 printf("Enter the elements in the stack:\n");
10
11 for (i = 0; i < 5; i++) {
12 scanf("%d", top++);
13 }
14
15 printf("The address associated with those elements are:\n");
16 for (i = 0; i < 5; i++) {
17 printf("%d is at %u\n", *--top, top);
18 }
19
20 getch();
21 }
22
23
OUTPUT

Enter the elements in the stack: 1 2 3 4 5


The address associated with those elements are:
5 is at 6422292
4 is at 6422288
3 is at 6422284
2 is at 6422280

1 is at 6422276

You might also like