Memory Location

This is a discussion on Memory Location within the C Programming forums, part of the General Programming Boards category; Hi friends this is my first posting . i greet you all . my query : main() { int a=10; ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    4

    Lightbulb Memory Location

    Hi friends this is my first posting . i greet you all .



    my query :

    main()

    {

    int a=10;

    printf("%x",&a);

    printf("%x",&a++);

    }

    what should i write in the red portion so as to get the next memory location after
    a without using pointers .


    Hope somebody solves my query .
    Bye
    Som

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    &a + sizeof( a )
    That should suffice.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    4
    Hi Quzah ,
    thanx for your reply , but how do i get the next --next-- next addresses if i put the printf command in a loop .

    Som

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    I fail to see what this proves you can do, if you can do it without pointers

    Answer snipped
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It should be trivial. Think about it for a bit. How do you normally work your way through an array? How do you do it if you want to skip ahead by two or three or N each time? Apply that same logic to this problem.

    Post your attempt, and we'll give you hints. Or, if you wait around long enough, someone will doubtless show up and do the whole thing for you. It never fails.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Apr 2004
    Posts
    4
    thanx Quzah for the encouragement , it really pegged me to go and get the ans .:

    printf("\n%x",&a + i+sizeof( a ));

    with thanx

    Som

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Or you could always do:
    Code:
    for( i = 0; i < foo; i++ )
        printf("%x\n", &a + (i*sizeof(a)) );
    This way you don't have to add sizeof( a ) to what you have down as i in your version.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-06-2009, 11:27 AM
  2. Memory allocation/reallocation
    By magda3227 in forum C Programming
    Replies: 10
    Last Post: 07-04-2008, 03:27 PM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 12:33 PM
  4. Location of member functions in memory
    By bennyandthejets in forum C++ Programming
    Replies: 4
    Last Post: 12-05-2003, 08:30 AM
  5. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 04:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21