please tell it works

V

venkatesh

hai to everybody
i am trying some coding as such flow it works or not
code is


int *p;
*p=20
printf("%d",*p);
 
G

GJ

p will be containing some garbage address make this code highly vulnerable
for segmentation fault :-(
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
hai to everybody
i am trying some coding as such flow it works or not
code is


int *p;
*p=20
printf("%d",*p);

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)

iD8DBQFDV5fhagVFX4UWr64RAnc6AJ43kLASHNqZ9bJ3RvCcnnOsQIgVowCcDsyb
t2RW5qNDmPwxoJs+ApmQ/zw=
=RpKA
-----END PGP SIGNATURE-----
 
C

Chris Dollin

venkatesh said:
hai to everybody
i am trying some coding as such flow it works or not
code is


int *p;
*p=20
printf("%d",*p);

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.
 
V

venkatesh

thank you for your guidance i will not except with example. nice it is
very helpful to understand pointers
 
M

Mistakenidentity18

I like to join with your group.
Pls add me.
Thanx a million

-
Mistakenidentity
 
R

Randy Howard

venkatesh wrote
(in article
thank you for your guidance i will not except with example. nice it is
very helpful to understand pointers

Have you been watching the Star Wars series on DVD lately?
 
S

Skarmander

Randy said:
venkatesh wrote
(in article



Have you been watching the Star Wars series on DVD lately?

Somehow Yoda doesn't strike me as a C hacker, but maybe that's just me.
I'd figure him more of a lambda calculus type.

S.
 
T

Tim Rentsch

Randy Howard said:
venkatesh wrote
(in article


Have you been watching the Star Wars series on DVD lately?

"On DVD the Star Wars series been watching lately have you?"

(Sorry, I couldn't resist. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,924
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top