#include <stdio.h>
void Initialize (char * a, char * b)
{
a[0] = 'T'; a[1] = 'h'; a[2] = 'i';
a[3] = 's'; a[4] = ' '; a[5] = 'i';
a[6] = 's'; a[7] = ' '; a[8] = 'A';
a[9] = '\0';
b = a;
b[8] = 'B';
}
#define ARRAY_SIZE 10
char a[ARRAY_SIZE];
char b[ARRAY_SIZE];
int main(int argc, char * argv[])
{
Initialize(a, b);
printf("%s\n%s\n", a, b);
return 0;
}
When you run this program, only "This is B" is printed. To see why, place a
breakpoint in the line b[8] = 'B' and rerun the program. Take a look at the values
of a and b. They are the same, as they should be, because we assigned a to b in the
previous line. What is the same, however, is not the
contents
of the arrays but
the two arrays have the same address after the assignment b = a. The contents are
not only equal, they
are
the same. Modifying one will also modify the other. The
assignment b[8] = 'B' will modify the bits of memory that also contain a[8], and
the contents of the original b will remain untouched. The two original arrays
still get printed, but the first one will now contain "This is B" and the second
will be empty because it was never touched. The address of the second one, which
was allocated by the compiler when it was declared, was overwritten and discarded
by the line b = a before its contents were modified.
分享到:
相关推荐
[基于QoS的资源分配与收发机优化]QoS-Based Resource Allocation and Transceiver Optimization
在"LINUX下的C语言高级编程"这一主题中,我们探讨...通过这些章节的学习,开发者不仅可以提升在Linux系统下使用C语言进行编程的能力,还能深入理解底层操作系统的工作原理,这对于系统级编程和软件开发有着极大的帮助。
Resource allocation and cross-layer control in wireless networks
通过这些详细的介绍可以看出,《DB2 SQL Reference》不仅是一本参考手册,更是学习DB2数据库管理系统的宝贵资源。它不仅涵盖了基本的命令和操作,还深入到了高级功能和技术细节。对于希望深入了解和掌握DB2数据库的...
在计算机科学领域,**动态存储分配**一直是操作系统内核、编程语言运行时环境及应用程序性能的关键因素。Paul R. Wilson 等作者的这篇论文《Dynamic Storage Allocation: A Survey and Critical Review》是对自 1960...
### 跨层资源分配与调度在多用户空间时间分组编码MIMO-OFDM系统中的应用 #### 摘要解读 本文提出了一种适用于多用户MIMO/OFDM系统的跨层自适应资源分配和调度方法。具体而言,研究考虑了一个结合了空间时间分组...
### SSD6名词解释与系统级编程 #### 1. Alignment(对齐) **定义与作用:** 对齐是指编译器在编译过程中为了优化内存访问速度和提高数据处理效率而进行的一种操作。通常,编译器会尝试将数据边界(如单词或双词)...
indoor coverage and spatial reuse gains in the last few years. Femtocells are low power, low cost and user deployed wireless access points that use local broadband connections as backhaul. Not only ...
Lecture 2-C Library Interfacing and Allocation 本资源是中田纳西州立大学 CS3130 《汇编与计算机组成》课件,主要讲解 C 语言库接口和静态数据分配。在本讲义中,我们将学习 C 语言编程、汇编语言、静态数据分配...
《操作系统实验:Allocation & Reclaim》 实验报告的焦点在于操作系统如何管理主存空间的分配与回收,特别是在可变分区管理方式下运用最先适应算法。这个实验旨在加深对操作系统核心功能的理解,即如何有效地利用...
3.12 dup and dup2 Functions 79 3.13 sync, fsync, and fdatasync Functions 81 3.14 fcntl Function 82 www.it-ebooks.info Contents xi 3.15 ioctl Function 87 3.16 /dev/fd 88 3.17 Summary 90 Chapter 4. ...
Design_and_Implementation_of_GCC_Register_Allocation ........................................................................... ....................................................... ..................
Allocation Tracker 的使用 Allocation Tracker 是一个强大的工具,用于追踪内存分配信息。它可以在 Android Studio(AS)和 Eclipse 中使用。 Allocation Tracker 提供了详细的内存分配信息,帮助开发者更好地了解...
MATLAB作为一款高级编程语言和交互式环境,被广泛应用于科学计算、算法开发以及数据分析等领域。在金融行业中,MATLAB因其强大的数学处理能力和便捷的数据可视化功能,成为风险分析和模型构建的理想选择。本书利用...
效用理论是衡量投资者满意度的工具,风险规避的效用函数通常表现为U = E(r) - 1/2 * A * s^2,其中U是效用,E(r)是期望收益,A是风险规避系数,s^2是收益的方差。较高的风险规避系数会导致投资者对波动性强的资产...
In this paper, we study the resource allocation algorithm design for multiuser orthogonal frequency division multiplexing (OFDM) downlink systems with simultaneous wireless information and power ...
The flow capturing and the p-median location-allocation models deal quite differently with demand for service in a network. The p-median model assumes that demand is expressed at nodes and locates ...