面试问题? [英] Interview question?

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

问题描述

void main()

{

int i = 20;

void fn();

fn();


printf("%d",i);

}


void fn ()

{

//只在这里添加你的代码,这样我在主要的应该打印其他20以上

}


是否有任何Leagal解决方案?

谢谢,

void main()
{
int i = 20;
void fn();
fn();

printf ("%d",i);
}

void fn()
{
// add ur code only here so that i in main should print OTHER THAN 20
}

Is there any Leagal solution for this?
Thanks,

推荐答案

在文章< sl ******************* @ nospam.invalid> ;, Padmat< no@spam.comwrote:
In article <sl*******************@nospam.invalid>, Padmat <no@spam.comwrote:

> void main()

int i = 20;

void fn();

fn();


printf("%d",i);
}

void fn()
{

//只在这里添加你的代码,这样我在主应该打印其他20以上

是否有任何Leagal解决方案?
谢谢,
>void main()
{
int i = 20;
void fn();
fn();

printf ("%d",i);
}

void fn()
{
// add ur code only here so that i in main should print OTHER THAN 20
}

Is there any Leagal solution for this?
Thanks,



我已经重新安排了你的代码,使其更符合clc标准

(虽然没有完全合规的声明 - 我确定regs会

拿出一些东西来挑剔)。请注意缺少的包括

已经使您的程序UB。


%cat xc

void fn()

{

//只在这里添加你的代码,这样我在主要的应该打印除了20

}


#include" stdio.h"

int main()

{

int i = 20;

fn();


printf(" i =%d \ n",i);

返回0; < br $>
}


%gcc -Wall -Werror xc

%。/ a.out

i = 13



HTH

I''ve re-arranged your code a bit, to make it a bit more clc-compliant
(though no claim of full compliance is made - I''m sure the regs will
come up with something to nitpick). Note the missing include that would
have made your program UB.

% cat x.c
void fn()
{
// add ur code only here so that i in main should print OTHER THAN 20
}

#include "stdio.h"

int main()
{
int i = 20;
fn();

printf ("i = %d\n",i);
return 0;
}

% gcc -Wall -Werror x.c
% ./a.out
i = 13
%

HTH


2008年2月1日20:21 ,Padmat写道:
On 1 Feb 2008 at 20:21, Padmat wrote:

void main()

{

int i = 20;

void fn();

fn();


printf("%d",i);

}


void fn()

{

//只在这里添加你的代码,以便我在main中打印除了20

}

是否有任何Leagal解决方案?

谢谢,
void main()
{
int i = 20;
void fn();
fn();

printf ("%d",i);
}

void fn()
{
// add ur code only here so that i in main should print OTHER THAN 20
}

Is there any Leagal solution for this?
Thanks,



这是Linux / gcc-的解决方案I386。我不得不让我挥发来停止

gcc优化它。

#include< stdio.h>


#定义OFFSET 8 / *可能需要根据您的编译器进行更改* /


main()

{

volatile int i = 20;

void fn();

fn();


返回printf("%d \ n,i);

}


void fn()

{

volatile int b;

*(& b + OFFSET)= 42;

}


快乐的黑客攻击!

Here is a solution for Linux/gcc-i386. I had to make i volatile to stop
gcc optimizing it away.
#include <stdio.h>

#define OFFSET 8 /* may need to change this depending on your compiler */

main()
{
volatile int i = 20;
void fn();
fn();

return printf ("%d\n",i);
}

void fn()
{
volatile int b;
*(&b + OFFSET)=42;
}

Happy hacking!


Padmat写道:
Padmat wrote:

>

void main()

{

int i = 20;

void fn();

fn();


printf("%d",i);

}


void fn()

{
//只在这里添加你的代码,这样我在主要的应该打印除了20

}


是否有任何Leagal解决方案?

谢谢,
>
void main()
{
int i = 20;
void fn();
fn();

printf ("%d",i);
}

void fn()
{
// add ur code only here so that i in main should print OTHER THAN 20
}

Is there any Leagal solution for this?
Thanks,



/ * BEGIN new.c * /


#include< stdio.h>


void fn(void);


int main(无效)

{

int i = 20;


fn();

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

返回0;

}


void fn(无效)

{

printf(" OTHER)相当于);

}


/ * END new.c * /


-

pete

/* BEGIN new.c */

#include <stdio.h>

void fn(void);

int main(void)
{
int i = 20;

fn();
printf("%d\n", i);
return 0;
}

void fn(void)
{
printf("OTHER THAN ");
}

/* END new.c */

--
pete


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

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