Unable to understand , how next address is getting computed in array , when performing operation &arr+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) ?
c
marked as duplicate by Davis Herring, Mad Physicist, Jonathan Leffler
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.
add a comment |
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) ?
c
marked as duplicate by Davis Herring, Mad Physicist, Jonathan Leffler
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
add a comment |
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) ?
c
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
c
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
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
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
&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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
&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
add a comment |
&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
add a comment |
&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
&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
answered Jan 1 at 5:16
SbrTaSbrTa
8412
8412
add a comment |
add a comment |
Pointers cannot be printed with
%u
. You must convert them to(void *)
and print them with%p
.– Antti Haapala
Jan 1 at 7:43