• Check the address of top of the stack


    Compile and run this small test program to discover the approximate location of the stack
    on your system:
    #include <stdio.h>
    main()
    {
    int i;
    printf("The stack top is near %p\n", &i);
    return 0;
    }
    Discover the data and text segment locations, and the heap within the data segment, by
    declaring variables that will be placed in those segments and printing their addresses. Make
    the stack grow by calling a function, and declaring some large local arrays.
    What's the address of the top of the stack now?
    The stack may be located at a different address on different architectures and for different OS
    revisions. Although we talk about the top of the stack, the stack grows downwards on most processors,
    towards memory addresses with lower values.

8 comments:

  1. VTUENGINES said...

    Answer posted by Admin for Sorting Stack

    #include
    #include
    #include

    typedef struct node
    {
    int data;
    node *next;
    }node;
    void sort(node*);
    void main()
    {
    clrscr();
    node *top,*p;
    int size=0;
    printf("\nenter the no. of nodes");
    scanf("%d",&size);
    printf("\n Enter the data");
    top=(node*)malloc(sizeof(node));
    scanf("%d",&(top->data));
    top->next=NULL;
    //p=top;
    for(int i=0;idata));
    p->next=top;
    top=p;
    }
    // procedure to print
    p=top;
    while(p!=NULL)
    {
    printf("\n%d",p->data);

    p=p->next;
    }

    // procedure to sort
    sort(top);
    getch();
    }

    void sort(node *top)
    { int temp;
    node *p,*r;
    r=top;
    while(top!=NULL)
    { p=top->next;
    while(p!=NULL)
    {
    if(top->data > p->data)
    {
    temp=top->data;
    top->data=p->data;
    p->data=temp;
    }
    p=p->next;

    }
    top=top->next;

    }
    printf("\nafter sorting:-");
    while(r!=NULL)
    {
    printf("\n%d",r->data);
    r=r->next;
    }


    }

    thank u admin

  2. Unknown said...

    for what buddy? this program?
    if ya? then its ok.

  3. Anonymous said...

    PLEASE EXPLAIN THIS PROGRAMM PLSSSSSS ADMIN..
    I WANT TO LEARN...PLSSSSSS
    PLS EXPLAIN

  4. Unknown said...

    which program?

  5. VTUENGINES said...

    ask admin bro am little busy...
    pls ask admin he did it..today afternoon

  6. Unknown said...

    Above progrm Daarks...just explin me in comments,,,mainly tat sorting functing...and pls post some books on c..learning..

  7. Unknown said...

    I have already uploaded some of them. check the older posts

  8. Unknown said...

    learn through example
    10,3,4,5
    TOP- 10
    p-3
    (10 >3)
    swap them.
    next iteration : 3,10,4,5
    top:10 ,p:4
    (10>4) swap them
    next iteration : 3,4,10,5 and so on...

Post a Comment