紧急C问题 [英] Urgent C Questions

查看:78
本文介绍了紧急C问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



1.在prg下面哪些变量存储在堆栈,堆,数据段上?


int i;


void main()

{

int j;

int * k =(void *)malloc(1) ;

}


(我认为j和k在堆栈上,但我在哪里?)

2.如何使用sizeof命令查找sizeofof w / o?


(无线索)

3.这个prg的o / p是多少?


void main()

{

int x = 5;

x = x ++;

printf(" x =%i",x);

}


(我认为它应该打印5但它打印6! )


ps:我使用的是QuickC 2.0


pps:非常紧急!


1. in the prg bellow what vars are stored on stack, heap, data segment?

int i;

void main()
{
int j;
int *k = (void *)malloc(1);
}

(I think j and k are on stack, but where is i?)
2. how to find sizeof variable w/o using sizeof command?

(no clue)
3. what is the o/p of this prg?

void main()
{
int x = 5;
x = x++;
printf("x=%i", x);
}

(I think it shoulld be printing 5 but it prints 6!)

ps: I am using QuickC 2.0

pps: Is very urgent!

推荐答案

在文章< 18 **************** @ aioe.org>,

Hans Schneider< ha * *@localhost.localdomainwrote:
In article <18****************@aioe.org>,
Hans Schneider <ha**@localhost.localdomainwrote:

> 1。在prg下面,哪些变量存储在堆栈,堆,数据段上?


int i;


void main()

{

int j;

int * k =(void *)malloc(1);

}

(我认为j和k在堆栈上,但我在哪里?)
>1. in the prg bellow what vars are stored on stack, heap, data segment?

int i;

void main()
{
int j;
int *k = (void *)malloc(1);
}

(I think j and k are on stack, but where is i?)



很多同样的问题是在不到一周前被问到的。

的答案是,就C而言,''stack'',''heap'',

和''data segment''是实现细节,符合

实现,不使用任何这些。

Very much the same question was asked less than a week ago. The
answer is that as far as C is concerned, ''stack'', ''heap'',
and ''data segment'' are implementation details and conforming
implementations exist which do not use any of those.


> 2。如何使用sizeof命令找到sizeof变量?
>2. how to find sizeof variable w/o using sizeof command?


>(无线索)
>(no clue)



这是在C FAQ中。

This is in the C FAQ.


> 3。什么是这个prg的o / p?


void main()

{

int x = 5;

x = x ++;

printf(" x =%i",x);

}

(我认为它应该打印5但它打印6!)
>3. what is the o/p of this prg?

void main()
{
int x = 5;
x = x++;
printf("x=%i", x);
}

(I think it shoulld be printing 5 but it prints 6!)



输出可以是任何东西,因为程序违反了

约束,有一个不正确的声明声明,并没有#include

a必要的界面文件。

-

所有都是虚荣。 - Ecclesiastes

The output can be anything at all, as the program violates a
constraint, has an incorrect declaration for main, and fails to #include
a necessary interface file.
--
"All is vanity." -- Ecclesiastes


2008年1月15日星期二03:41:56 + 0100(CET),Hans Schneider

< ha **在comp.lang.c中@ localhost.localdomainwrote:


因为它是一个C问题,是否紧急,它必须是关于

有效C代码。
On Tue, 15 Jan 2008 03:41:56 +0100 (CET), Hans Schneider
<ha**@localhost.localdomainwrote in comp.lang.c:

For it to be a C question, urgent or not, it would have to be about
valid C code.

1.在prg下面,哪些变量存储在堆栈,堆,数据段上?


int i;


void main()
1. in the prg bellow what vars are stored on stack, heap, data segment?

int i;

void main()



上面的行生成未定义的行为,而不是有效的C代码。

The line above generates undefined behavior, not valid C code.


{

int j;

int * k =(void *)malloc(1);
{
int j;
int *k = (void *)malloc(1);



由于范围内没有malloc()的原型,未定义的行为,

无效的C代码。

Since there is no prototype for malloc() in scope, undefined behavior,
not valid C code.


}


(我认为j和k在堆栈上,但我在哪里?)


2.如何使用sizeof命令查找sizeof变量?


(无线索)
}

(I think j and k are on stack, but where is i?)
2. how to find sizeof variable w/o using sizeof command?

(no clue)



没有sizeof命令,不是有效的C问题。

There is no sizeof command, not a valid C question.


3.这个prg的o / p是多少?


void main()
3. what is the o/p of this prg?

void main()



上面的行生成未定义的行为,而不是有效的C代码。

The line above generates undefined behavior, not valid C code.


{

int x = 5;

x = x ++;
{
int x = 5;
x = x++;



上面的行生成未定义的行为,而不是有效的C代码。

The line above generates undefined behavior, not valid C code.


printf(" x = %i,x);
printf("x=%i", x);



由于范围内没有printf()的原型,这会导致

未定义的行为,而不是有效的C代码。

Since there is no prototype for printf() in scope, this causes
undefined behavior, not valid C code.


}


(我认为它应该打印5但它打印6!)
}

(I think it shoulld be printing 5 but it prints 6!)



我认为它应该打印,这段代码是由一个白痴写的!

I think it should print, "This code was written by an idiot!".


ps:我正在使用QuickC 2.0


pps:非常紧急!
ps: I am using QuickC 2.0

pps: Is very urgent!



对不起,这些是关于C语言的问题。如果你是一个实际的C编程课程,并且你的导师问了这些

的家庭作业问题,请执行以下操作:


1.立即放弃课程。


2.向学校管理部门投诉不合格的

教练和错误的材料。
< br $> b $ b -

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://c-faq.com/

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html

Sorry, non of these is a question about the C language. If you are in
an actual C programming course, and your instructor asked these
questions for a homework assignment, do the following:

1. Immediately drop the class.

2. Complain to the school administration about the unqualified
instructor and erroneous material.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html


Hans Schneide r< ha ** @ localhost.localdomainwrites:
Hans Schneider <ha**@localhost.localdomainwrites:

1.在prg下面,哪些变量存储在堆栈,堆,数据段上?


int i;


void main()

{

int j;

int * k =(void *)malloc(1);

}


(我认为j和k在堆栈上,但在哪里是我?)


2.如何使用sizeof命令查找sizeof变量?


(无线索)


3.这个prg的o / p是多少?


void main()

{

int x = 5;

x = x ++;

printf(" x =%i",x);

}


(我认为它应该打印5但它打印6个!)


ps:我正在使用QuickC 2.0


pps:非常紧急!
1. in the prg bellow what vars are stored on stack, heap, data segment?

int i;

void main()
{
int j;
int *k = (void *)malloc(1);
}

(I think j and k are on stack, but where is i?)
2. how to find sizeof variable w/o using sizeof command?

(no clue)
3. what is the o/p of this prg?

void main()
{
int x = 5;
x = x++;
printf("x=%i", x);
}

(I think it shoulld be printing 5 but it prints 6!)

ps: I am using QuickC 2.0

pps: Is very urgent!



您迫切需要阅读< http://www.c-faq.com>。


如果你故意开始提出已被问过的问题

在这里被无知的新手重复(没有冒犯),你不可能做得更好

a更好的工作。我不是在指责你,但巧合是有点麻烦。


顺便说一下,问题#2并不难回答。使用sizeof

运算符。 (C没有sizeof *命令*。)


-

Keith Thompson(The_Other_Keith)< ks *** @ mib.org>

诺基亚

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

You urgently need to read <http://www.c-faq.com>.

If you had deliberately set out to ask questions that have been asked
here repeated by clueless newbies (no offense), you couldn''t have done
a much better job. I''m not accusing you, but the coincidence is a bit
troubling.

Incidentally, question #2 isn''t hard to answer. Use the sizeof
operator. (C has no sizeof *command*.)

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


这篇关于紧急C问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆