Home > Back-end >  C language pointer function and the return address
C language pointer function and the return address

Time:03-16

Just learn this freshman, data type is not learn
Define a type int function value of the return address, in the main function definition dereferencing a pointer variable
Whether and defines a pointer to function is the same as
Address is not the integer, defined type is the way of open the string of data, I think should be, is there any bosses to solve the problem of

It means about the code I know a bit of a problem, is this meaning

CodePudding user response:

 # include & lt; stdio.h> 
Int (c);
Int main ()
{
Char * b;
B=(char *) c ();
Printf (" % c ", * b);//h
return 0;
}
Int (c)
{
Char a='h'.
int b;
B=(int) & amp; a;
return b;
}

CodePudding user response:

A function pointer is the address of the function, not function returns the address of the data, different
Your code can display correctly is the address on the stack is not using the program ended, such code is not safe

CodePudding user response:

I know that this code is a bit of a problem, I mean if you define a char * p functions are defined and an int () function returns the address and reference solution in the main function is the same

CodePudding user response:

Although I know someone who can wear on the outside and then still jet-setting,
But I'm not that person, I still stick to wear underwear inside,

CodePudding user response:

Is the same,
In terms of Pointers to more consider is the width of the type,
Address is as long as the width of the data can be stored enough,
Char 1 byte
Short 2 bytes
All types int and pointer (pointer) is 4 bytes

So it is equivalent to (address) data to int and then to the char * (pointer) does not affect,
  • Related