|
-
Aug 27th, 2002, 07:24 PM
#1
Thread Starter
Hyperactive Member
What's wrong with this?
This is C source code... not c++
#include <stdio.h>
int x;
int *xpos;
x = 13;
xpos = &x;
printf("%i\n",x);
printf("%p\n\n",xpos);
-
Aug 27th, 2002, 07:28 PM
#2
Frenzied Member
um what are i and n and why do you need a pointer
Magiaus
If I helped give me some points.
-
Aug 27th, 2002, 07:34 PM
#3
Thread Starter
Hyperactive Member
I need a pointer because I am learning C and want to learn how to use them. I want to declare a variable... make a pointer variable point to it, and then print the original variable and the memory location of that variable... aka the pointer.
-
Aug 27th, 2002, 08:26 PM
#4
Frenzied Member
here run this
don't use stdio.h usiostream just because i say so and i don't like stdio
Code:
#include <iostream.h>
int main(){
int i = 27;
int *pi = &i;
cout<<"i="<<i<<"\n";
cout<<"&pi="<<&pi<<"\n";
return 0;
}
Magiaus
If I helped give me some points.
-
Aug 27th, 2002, 09:20 PM
#5
Frenzied Member
He specifically said C, so <iostream.h> is out. Even with C++, it is recommended that you use <iostream>, the newer header file.
Anyway, try changing the %p to a %i. It should print out the decimal value of the pointer.
Z.
-
Aug 28th, 2002, 05:46 AM
#6
Magiaus: the %i means print an integer, the \n is a newline.
zer0_flaw: Do you have a main function in your app?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Aug 28th, 2002, 10:24 AM
#7
Frenzied Member
yhanks bee man i new what the newline escape char was after i looked at his code closer i just wasn't familer with the 96i
plus i don't know straight c so.... i guess i shouldn't answer questions unless i know what i'm talking about
Magiaus
If I helped give me some points.
-
Aug 28th, 2002, 10:52 AM
#8
My bad side just won my internal discussion whether I should post to state that I won't comment on that or not.
Whatever...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Aug 28th, 2002, 11:27 AM
#9
Frenzied Member
ater debating i decided to post and say cornedbee is the man
Magiaus
If I helped give me some points.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|