Behavior is undefined since ptr2 does not point anywhere.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Did you try compiling it and running it?s s
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
The code you given has some error, are you sure you are giving the right code?
Anyway, the output should be:
x x
cause ptr1 has been assigned to the address of var2. When you output the value of *ptr1, it will refer to the value of that address.
What are you talking about?i need to know the data types of variables such as:
double var1, *ptr1, *ptr2;
float *ptr3;
int var2, *var4....do you know anything about data types????
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
var1 is a double
ptr1 is a pointer to double
...you should be able to handle it from here.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
so what would the data type of ptr1 be? would it be just ptr1 since it doesn't have the (*) in front of it or how does that work?
Uh, look up a couple posts where I answered that.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
-----------------------------------------------------------
output will be
X X
because ptr1 point to the var2 and var2 contain value 'x';
Not necessarily. At that point dereferencing an uninitialized pointer has caused undefined behavior. After that, nothing is guaranteed to work, even if it would otherwise.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401