if I declare a int variable a, and a int *p, let p point to a, p = &a;
can I say *p == a; at the moment?
if I declare a int variable a, and a int *p, let p point to a, p = &a;
can I say *p == a; at the moment?
p = &a; //put the address of 'a' into 'p'
*p = a; // assign the value of a to whatever p points at.
Example:
Quzah.Code:#include <stdio.h> int main ( void ) { int x, a, *p; a = 20; printf("A is %d.\n", a ); p = &a; *p = 40; printf("A is now %d.\n", a ); x = 10; *p = x; printf("A is now %d.\n", a ); return 0; }
Hope is the first step on the road to disappointment.
if I say int a, *p;
a = 20; p = &a; and
*p == a ?
I think that would work, have you tried it?
Well the double equal sign is for conditions such as:
if(*p == 10)
//then execute this...
Also, if you have an array of ints, you can use pointer arithmatic after assigning a pointer to it:
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int *p;
p = array;
while(*p) // loops till it reaches end of "array"!
{
if(*p==5)
printf("Equals five\n");
else if(*p < 5)
printf("Less than five\n");
else
printf("Greater than five\n");
p++; //increments through "array"
}
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Yes. You are dereferencing p (which points to a) and comparing it with a.......therefore you are comparing a with itself.....Originally posted by pnxi
if I say int a, *p;
a = 20; p = &a; and
*p == a ?
Hi!
p points to a
then p stands for the address the pointer is pointing to, itīs the address of a and *p stands for the value in that address, itīs the value of a.
klausi
When I close my eyes nobody can see me...
Bingo.
-Govtcheez
[email protected]