English 中文(简体)
印刷在记忆分配中是否有任何作用?
原标题:Is there any role of printf in memory allocation?

本条准则

#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j, k, l;
int *ii = (int *)malloc(sizeof(int));
int *jj = (int *)malloc(sizeof(int));
int *kk = (int *)malloc(sizeof(int));
int m, n, o, p;
// Call below line as star line
printf("%u %u %u %u %u %u %u %u %u %u %u
",&i,&j,&k,&l,&ii,&jj,&kk,&m,&n,&o,&p);
// Call below line as delta line
printf("%u %u %u %u %u %u %u %u %u %u %u
",&i,&j,&k,&l,ii,jj,kk,&m,&n,&o,&p);
 return 0;
}

取得这一产出

2293516 2293512 2293508 2293504 2293500 2293496 2293492 2293488 2293484 2293480 2293476
2293516 2293512 2293508 2293504 3739288 3739320 3739336 2293488 2293484 2293480 2293476

直到现在为止,一切都很清楚,但当我评论时,光线产出就变成了。

2293520 2293516 2293512 2293508 4525720 4525752 4525768 2293504 2293500 2293496 2293492

我的问题是,在这种情况下,记忆点不是毗连的。 在第二行,第一胎的数值为4个按特约,即516、512、508、504个,然后是3个地点,然后是488、484、480个,但第二点的数值为520、516、512、508个,然后是3个地点,然后是504、500、496个。 为什么508年以后的下一个数值是504,而应该是492? 这里是否有任何印刷作用?

最佳回答

汇编者可自行安排当地变量,但可以发现这些变量是合适的。

当地变数是连续储存的,或两者之间没有姓名的dding,或储存在某一个记忆中,没有任何保障。

也没有保证地方变量实际上完全在运行时存在。 例如,当你发表第1条<代码>f时,当地变量iijjk从未被使用作为“ l Values(实质上,你从未做过任何需要标的地址),因此汇编者可以选择完全消除这些变量。

在你的具体例子中,汇编者可能决定在同一地点储存所有三个变数,或者因为你从来不会首先将变数——即只能使用其他地点随机内容的记忆,而后者同样是“有效”行为。

问题回答

暂无回答




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签