请告诉它有效 [英] please tell it works

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

问题描述

hai to everybody

i我正在尝试一些编码,因为这样的流程是否有效

代码是

int * p;

* p = 20

printf("%d",* p);

hai to everybody
i am trying some coding as such flow it works or not
code is
int *p;
*p=20
printf("%d",*p);

推荐答案

p将包含一些垃圾地址使此代码极易受到攻击

分段错误:-(


-

GJ

" venkatesh"< pv *********** @ gmail.com>写在留言中

news:11 ** ******************** @ g47g2000cwa.googlegr oups.com ...
p will be containing some garbage address make this code highly vulnerable
for segmentation fault :-(

--
GJ
"venkatesh" <pv***********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
hai to everyone's
我正在尝试一些编码这样的流程是否有效
代码是

int * p;
* p = 20
printf("%d",* p);
hai to everybody
i am trying some coding as such flow it works or not
code is
int *p;
*p=20
printf("%d",*p);



----- BEGIN PGP签名消息-----

哈希:SHA1

venkatesh写道:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

venkatesh wrote:
hai to everyonebody
我正在尝试一些编码,因为这样的流程是否有效
代码是

int * p;
* p = 20
printf("%d",* p);
hai to everybody
i am trying some coding as such flow it works or not
code is
int *p;
*p=20
printf("%d",*p);




除了事实上这些陈述不构成有效的C程序或

函数,因此它们是不可编译的,我只看到你的代码有一个问题。

。您将p声明为/指针/指向整数,但从不将p初始化为

包含指针值。

int * p;
单独
不足以允许正确操作

* p = 20;

因为p没有值。


你的代码看起来应该是......


#include< stdio.h> ; / * for printf()prototype * /

void myfunction(void)

{

int * p; / *指针的位置* /

int q; / *一个整数的位置* /


p =& q; / *初始化p指向int q * /

* p = 20; / *初始化p现在指向* /


printf("%d \ n",* p); / *打印int值* /

}

- -

Lew Pitcher

IT专家,企业数据系统,

企业技术解决方案,道明银行金融集团


(表达的意见是我自己的,而不是我的雇主')

----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.2.4(MingW32)

iD8DBQFDV5fhagVFX4UWr64RAnc6AJ43kLASHNqZ9bJ3RvCcnn OsQIgVowCcDsyb

t2RW5qNDmPwxoJs + ApmQ / zw =

= RpKA

----- END PGP SIGNATURE -----



Besides the fact these statements do not constitute a valid C program or
function, and thus are uncompilable as they stand, I only see one problem with
your code. You declare p as a /pointer/ to an integer, but never initialize p to
contain a pointer value. the
int *p;
alone is insufficient to permit the proper operation of
*p=20;
because p does not have a value.

Your code should look something like....

#include <stdio.h> /* for printf() prototype */
void myfunction(void)
{
int *p; /* a place for a pointer */
int q; /* a place for an integer */

p = &q; /* initialize p to point to int q */
*p = 20; /* initialize the int that p now points to */

printf("%d\n",*p); /* print the int value */
}
- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers'')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFDV5fhagVFX4UWr64RAnc6AJ43kLASHNqZ9bJ3RvCcnn OsQIgVowCcDsyb
t2RW5qNDmPwxoJs+ApmQ/zw=
=RpKA
-----END PGP SIGNATURE-----

< br>

venkatesh写道:
venkatesh wrote:
hai to everyone
我正在尝试一些编码,因为这样的流程是否有效
代码是

int * p;
* p = 20
printf("%d",* p);
hai to everybody
i am trying some coding as such flow it works or not
code is
int *p;
*p=20
printf("%d",*p);




假设你通过将

放在一个函数中并使用相应的include来使这段代码在语法上合法化:


#include< stdio.h>


无效xample(void)

{

int * p;

* p = 20;

printf(" %d",* p);

}


然后人们可以合理地问`* p = 20`," where / do / you

认为20将被存储?


还可以希望进一步的,换行终止,

输出应该在`example`被调用之后发生。


-

克里斯电刺猬 Dollin

Il Principe - Byzantium - Hansa - Antike - King''s Progress

Farfalia - Mu - Havoc - Tigris&幼发拉底河[kartenspiel]



Suppose you made this code syntactically legal by putting it
inside a function and with the appropriate include:

#include <stdio.h>

void example(void)
{
int *p;
*p = 20;
printf( "%d", *p );
}

Then one could reasonably ask of `*p = 20`, "where /do/ you
think the 20 will be stored?".

One could also hope that some further, newline-terminated,
output is supposed to happen after `example` gets called.

--
Chris "electric hedgehog" Dollin
Il Principe - Byzantium - Hansa - Antike - King''s Progress
Farfalia - Mu - Havoc - Tigris & Euphrates [kartenspiel]


这篇关于请告诉它有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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