Unable to understand , how next address is getting computed in array , when performing operation &arr+1...












1
















This question already has an answer here:




  • What does getting address of array variable mean?

    7 answers




I am trying to understand array behavior. Please see the code below. Size of int is 4.



int arr={10,9,8,7,6,5};

printf("nSingle array print=> n%u || %u || %u || %u",
singlearr, &singlearr, &singlearr + 1);


I am getting the output:



2293248  ||  2293248  ||  2293272


I understand the expressions "singlarr" and "&singlearr" but when I am doing "&singlearr + 1", why it is giving output as 2293272 which is 24 bytes after the address 2293248 (2293248+24) ?










share|improve this question















marked as duplicate by Davis Herring, Mad Physicist, Jonathan Leffler c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 5:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Pointers cannot be printed with %u. You must convert them to (void *) and print them with %p.

    – Antti Haapala
    Jan 1 at 7:43
















1
















This question already has an answer here:




  • What does getting address of array variable mean?

    7 answers




I am trying to understand array behavior. Please see the code below. Size of int is 4.



int arr={10,9,8,7,6,5};

printf("nSingle array print=> n%u || %u || %u || %u",
singlearr, &singlearr, &singlearr + 1);


I am getting the output:



2293248  ||  2293248  ||  2293272


I understand the expressions "singlarr" and "&singlearr" but when I am doing "&singlearr + 1", why it is giving output as 2293272 which is 24 bytes after the address 2293248 (2293248+24) ?










share|improve this question















marked as duplicate by Davis Herring, Mad Physicist, Jonathan Leffler c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 5:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Pointers cannot be printed with %u. You must convert them to (void *) and print them with %p.

    – Antti Haapala
    Jan 1 at 7:43














1












1








1


1







This question already has an answer here:




  • What does getting address of array variable mean?

    7 answers




I am trying to understand array behavior. Please see the code below. Size of int is 4.



int arr={10,9,8,7,6,5};

printf("nSingle array print=> n%u || %u || %u || %u",
singlearr, &singlearr, &singlearr + 1);


I am getting the output:



2293248  ||  2293248  ||  2293272


I understand the expressions "singlarr" and "&singlearr" but when I am doing "&singlearr + 1", why it is giving output as 2293272 which is 24 bytes after the address 2293248 (2293248+24) ?










share|improve this question

















This question already has an answer here:




  • What does getting address of array variable mean?

    7 answers




I am trying to understand array behavior. Please see the code below. Size of int is 4.



int arr={10,9,8,7,6,5};

printf("nSingle array print=> n%u || %u || %u || %u",
singlearr, &singlearr, &singlearr + 1);


I am getting the output:



2293248  ||  2293248  ||  2293272


I understand the expressions "singlarr" and "&singlearr" but when I am doing "&singlearr + 1", why it is giving output as 2293272 which is 24 bytes after the address 2293248 (2293248+24) ?





This question already has an answer here:




  • What does getting address of array variable mean?

    7 answers








c






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 17:35







infiniteLearner

















asked Jan 1 at 4:52









infiniteLearnerinfiniteLearner

1179




1179




marked as duplicate by Davis Herring, Mad Physicist, Jonathan Leffler c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 5:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Davis Herring, Mad Physicist, Jonathan Leffler c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 5:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Pointers cannot be printed with %u. You must convert them to (void *) and print them with %p.

    – Antti Haapala
    Jan 1 at 7:43



















  • Pointers cannot be printed with %u. You must convert them to (void *) and print them with %p.

    – Antti Haapala
    Jan 1 at 7:43

















Pointers cannot be printed with %u. You must convert them to (void *) and print them with %p.

– Antti Haapala
Jan 1 at 7:43





Pointers cannot be printed with %u. You must convert them to (void *) and print them with %p.

– Antti Haapala
Jan 1 at 7:43












1 Answer
1






active

oldest

votes


















3














&arr is a pointer to an entire array. So, if we move &arr by 1 position it will point the next block of n elements.
If the array base address is b, &arr+1 will be b + (n * 4)



here, n=6 and b = 2293248
so, &arr+1 = b+(n*4) = 2293248 + (6*4) = 2293272






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    &arr is a pointer to an entire array. So, if we move &arr by 1 position it will point the next block of n elements.
    If the array base address is b, &arr+1 will be b + (n * 4)



    here, n=6 and b = 2293248
    so, &arr+1 = b+(n*4) = 2293248 + (6*4) = 2293272






    share|improve this answer




























      3














      &arr is a pointer to an entire array. So, if we move &arr by 1 position it will point the next block of n elements.
      If the array base address is b, &arr+1 will be b + (n * 4)



      here, n=6 and b = 2293248
      so, &arr+1 = b+(n*4) = 2293248 + (6*4) = 2293272






      share|improve this answer


























        3












        3








        3







        &arr is a pointer to an entire array. So, if we move &arr by 1 position it will point the next block of n elements.
        If the array base address is b, &arr+1 will be b + (n * 4)



        here, n=6 and b = 2293248
        so, &arr+1 = b+(n*4) = 2293248 + (6*4) = 2293272






        share|improve this answer













        &arr is a pointer to an entire array. So, if we move &arr by 1 position it will point the next block of n elements.
        If the array base address is b, &arr+1 will be b + (n * 4)



        here, n=6 and b = 2293248
        so, &arr+1 = b+(n*4) = 2293248 + (6*4) = 2293272







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 5:16









        SbrTaSbrTa

        8412




        8412

















            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

            A Topological Invariant for $pi_3(U(n))$