开发者

Write a function in c that includes the following sequence of statements [Wont Compile]

开发者 https://www.devze.com 2022-12-22 20:35 出处:网络
There is a question in my programming languages textbook that is as follows: Write a C function that includes the

There is a question in my programming languages textbook that is as follows:

Write a C function that includes the following sequence of statements:

x = 21; int x; x = 42;

Run the progr开发者_C百科am and explain the results. Rewrite the same code in C++ and Java and compare the results.

I have written code, and played with it in all three languages but I can not even get it to compile. This includes declaring x above the three lines as well as in the calling function (as this question is obviously attempting to illustrate scoping issues)

I'd like to explain the results and do the comparisons on my own, as it is an assignment question but I was wondering if anyone had any insight as to how to get this code to compile?

Thanks


Note the following requires C99:

int x;

void foo()
{
    x = 21;
    int x;
    x = 42;
}

Since this is homework, you'll need to provide your own explanation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号