Home > Back-end >  C address variable
C address variable

Time:09-25

Variables can define an address, the address to where the data type,

CodePudding user response:

. Refer to the original poster benny xuthus response:
variables can define an address, the address to where the data type,

Int? . .

CodePudding user response:

Void * :
Need to use what data type is strong to turn

CodePudding user response:

Char * should can actually, as long as it points to a byte address is enough, just make sure have enough room for different data types in a row,

CodePudding user response:

refer to the second floor stherix response:

void *!Need to use what data type is strong turn

CodePudding user response:

In an empty type first and subsequent conversion type

CodePudding user response:

Uncertain type, so how should know how much memory to allocate?

CodePudding user response:

Use malloc for a data type to create a block of memory to save the data you will understand

CodePudding user response:

If it is a function call, instantiation, want to use a different type of parameters can use a class template
The template & lt; The class T>//T for the type of the alias
 
# include
using namespace std;
The template & lt; The class T>
T add (T& Left, T& Right)
{
Return left + right;
}

Int main ()
{
Int a=3, b=2;
Double c=5.0, d=1.0;
Printf (" % d \ n ", add (a, b));
Printf (" % lf \ n ", add (c, d));
}

CodePudding user response:

Address is a pointer, & amp; A is a pointer constant, int * p, p pointer variable, you say the address of the variable is a pointer variable, pointing to the data type of the variable, you can use the void * p, p can point to any place where address arithmetic types can be automatically switched with other types, you can manually turn,
For example,
 
#include
Int main ()
{
Int a=5;
Double b=7;
Void * p=& amp; a;
Printf (" % d ", * (int *) p);//the cursor cast to type int * to visit
P=& amp; b;
Printf (" % f ", * * (double) p);
return 0;
}

Void * pointer to use the most is the function parameter, so no matter what type of pointer can receive,

CodePudding user response:

refer to the second floor stherix response:

void *!Need to use what data type is strong turn

Thanks.
  • Related