java为什么不设置指针,为什么不使用引用地址指针进行c编译工作?

我是一名新的计算机科学专业的学生,并参加了我的第一堂课 . 我学到了很多,这是我在堆栈交换上的第一篇文章 . 我有一个问题,了解我的代码发生了什么 . 我有两个问题 .

我会发布我的代码然后问我的问题 .

// This program uses the address of each element in the array.

#include

using namespace std;

int main()

{

const int NUM_COINS = 5;

int coins[NUM_COINS] = {5, 1, 25, 5, 10};

int *p1; // Pointer to a double.

int count; // Counter variable.

// Use the pointer to display the values in the array.

cout << "Here are the values in the coins array: \n";

for(count = 0; count << NUM_COINS; count++)

{

// Get the address of an array element

p1 = &coins[count];

// Display the contents of the element

cout << *p1;

}

cout << endl;

return 0;

}

所以我的第一个问题是为什么不编译呢?我的任何其他简单程序都没有任何问题 . 我在OS X 4.2.1上使用g . 我必须键入g -o命令才能编译,如果没有...我得到这些错误:

g -c -o 9-8.o 9-8.cpp cc 9-8.o -o 9-8未定义的符号:“std :: basic_ostream>&std :: operator <& ,char const *)“,引用自:9-8.o _main中的_main在9-8.o”std :: ios_base :: Init :: Init()“中,引自:static_initialization_and_destruction_0(int,int)in 9 -8.o“std :: basic_string,std :: allocator> :: size()const”,引自:std :: __ verify_grouping(char const *,unsigned long,std :: basic_string,std :: allocator> const&)在9-8.o“std :: basic_string,std :: allocator :: operator [](unsigned long)const”中,引自:std :: __ verify_grouping(char const *,unsigned long,std :: basic_string,std: :分配器> const&)在9-8.o std :: __ verify_grouping(char const *,unsigned long,std :: basic_string,std :: allocator> const&)in 9-8.o std :: __ verify_grouping(char const , 9-8.o“_gxx_personality_v0”中的unsigned long,std :: basic_string,std :: allocator> const&),引自:std :: __ verify_grouping(char const ,unsigned long,std :: basic_string,std :: allocator> const&)9 -8.o ___tcf_0 in 9-8.o main in 9-8.o unsigned long const&std :: min(unsigned long const&,unsigned long const&)in 9-8.o static_initialization_and_destruction_0(int,int)in 9-8 .o全局构造函数键入mainin 9-8.o CIE in 9-8.o“std :: ios_base :: Init :: ~Init()”,引自: tcf_0 in 9-8.o“std :: basic_ostream >&std :: endl(std :: basic_ostream>&)“,引用自:9-8.o中的_main”std :: basic_ostream :: operator <&()(std :: basic_ostream>&))“,引自:_8 in 9-8.o”std :: basic_ostream :: operator <

这导致了我的第二个问题 . 即使我输入g命令,它也会编译,但在运行后输出一个空数组 . 所以我的问题#2是:我的代码是否正确?如何正确使用带有引用地址语句的指针 .

谢谢 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值