关于C的一些问题 [英] Some questions about C

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

问题描述

你好朋友 -


任何人都可以回答这些C问题吗?


1.制作内部(本地)的影响是什么?变量静态?

2.使外部(非本地)变量静态有什么影响?

3.以下输出可能包括垃圾的内容代码?


int a = 10;

int b = 12;


ftn2(int a){

int c = 13;

printf("%d \ nn",a + b);

返回++ a;

}


ftn(int b){

b = a;

printf(" %d \ n",b);

返回ftn2(a);

}


void main()

{

int x = ftn(b);

printf("%d \ n",x);

}


感谢大家!

解决方案

Haskell Prelude说:


你好朋友 -


任何人都可以回答ese C问题?


1.使内部(本地)变量静态有什么影响?



假设你的意思是在函数范围定义的对象或更多本地的对象
,那么添加''static''存储类限定符给对象

静态存储持续时间,这意味着对象存在并保留

在整个程序执行期间的最后存储值

(3.1.2.4)。


2.使外部(非本地)变量静态有什么影响?



假设您指的是在文件范围定义的对象,添加''static''

存储类限定符对对象生命周期,因为这样的一个对象已经具有静态存储持续时间,因为它位于文件

范围内,但它确实限制了对象对翻译的可见性

单位当前正在翻译。


3.以下代码输出了什么,可能包括垃圾?



以下代码的行为(剪断)未定义至少

两个原因。

-

Richard Heathfield< http:// www .cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日


Haskell Prelude写道:


>

1.使内部(本地)变量静态有什么影响?



如果在本地你的意思是在函数范围内,那么它就变成了一个非自动变量,并在函数调用之间保留它的值。


2.使外部(非本地)变量静态有什么影响?



纯粹的愚蠢,如果非本地意味着文件范围。静态这里

阻止导出变量。


3.以下代码输出什么,可能包括垃圾?


int a = 10;

int b = 12;


ftn2(int a){

int c = 13;

printf("%d \ n",a + b);

返回++ a;

}


ftn(int b){

b = a;

printf("%d \ n" ,b);

返回ftn2(a);

}



如果你这些函数没问题刚刚定义了他们的返回类型

和#included< stdio.h>。对于C99,默认的int类型不再有效

。 ftn2打印(a + 13)的值并返回(a + 1)。

ftn忽略b的输入值,打印''10',然后是23,并返回

11.


>

void main()

{

int x = ftn(b);

printf("%d \ n",x);

}



这没有意义。 main ALWAYS返回一个int。你可以随时

返回0,或EXIT_FAILURE或EXIT_SUCCESS。非零值

需要#include stdlib.h。缺少#include< stdio.hmakes所有

printf语句纯粹是胡说八道。


像查询这样的作业通常会被忽略,但有

太多内置错误允许它不加批判。


-

Chuck F(cinefalconer at maineline dot net)

< http://cbfalconer.home.att.net>

尝试下载部分。

-

通过 http://www.teranews.com 上的免费Usenet帐户发布/>


Haskell Prelude写道:


你好朋友 -


任何人都可以回答这些C问题吗?


1.使内部(本地)变量静态有什么影响?

2.什么是使外部(非本地)变量静态的效果?

3.以下代码输出了什么,可能包括垃圾?



这些听起来像家庭作业问题。你应该真正阅读你的C $ / $
书和讲义。


>

void main()



不要这样做。

main()在C中返回一个int。


Hello Friends -

Can anyone answer these C questions?

1. What is the effect of making an internal (local) variable static?
2. What is the effect of making an external (non-local) variable static?
3. What, possibly including garbage, is output by the following code?

int a = 10;
int b = 12;

ftn2(int a) {
int c = 13;
printf("%d\n", a+b);
return ++a;
}

ftn(int b) {
b = a;
printf("%d\n", b);
return ftn2(a);
}

void main()
{
int x = ftn(b);
printf("%d\n", x);
}

Thanks to all!

解决方案

Haskell Prelude said:

Hello Friends -

Can anyone answer these C questions?

1. What is the effect of making an internal (local) variable static?

Assuming that you mean an object defined at function scope or more locally
than that, adding the ''static'' storage-class qualifier gives the object
static storage duration, which means that "the object exists and retains
its last-stored value throughout the execution of the entire program"
(3.1.2.4).

2. What is the effect of making an external (non-local) variable static?

Assuming that you mean an object defined at file scope, adding the ''static''
storage-class qualifier has no effect on object lifetime since such an
object already has static storage duration by virtue of being at file
scope, but it does restrict visibility of the object to the translation
unit currently being translated.

3. What, possibly including garbage, is output by the following code?

The behaviour of "the following code" (snipped) is undefined for at least
two reasons.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


Haskell Prelude wrote:

>
1. What is the effect of making an internal (local) variable static?

If by local you mean scoped within a function, then it becomes a
non-auto variable and preserves its value between function calls.

2. What is the effect of making an external (non-local) variable static?

Pure foolishness, if non-local means file scope. static here
prevents exporting the variable.

3. What, possibly including garbage, is output by the following code?

int a = 10;
int b = 12;

ftn2(int a) {
int c = 13;
printf("%d\n", a+b);
return ++a;
}

ftn(int b) {
b = a;
printf("%d\n", b);
return ftn2(a);
}

These functions would be fine if you just defined their return type
and #included <stdio.h>. The default int type is no longer valid
for C99. ftn2 prints the value of (a + 13) and returns (a + 1).
ftn ignores the input value of b, prints ''10'', then 23, and returns
11.

>
void main()
{
int x = ftn(b);
printf("%d\n", x);
}

This is meaningless. main ALWAYS returns an int. You can always
return 0, or EXIT_FAILURE or EXIT_SUCCESS. The non-zero values
require #include stdlib.h. Lack of #include <stdio.hmakes all
the printf statements pure nonsense.

This homework like query would normally be ignored, but there are
too many built in errors to allow it to go uncriticized.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com


Haskell Prelude wrote:

Hello Friends -

Can anyone answer these C questions?

1. What is the effect of making an internal (local) variable static?
2. What is the effect of making an external (non-local) variable static?
3. What, possibly including garbage, is output by the following code?

These all sound like homework questions. You should really read your C
book and lecture notes.

>
void main()

Don''t Do That.
main() returns an int in C.


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

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