I understand functions like data items have addresses and the address of a function is the memory address where the stored machine language code for the function begins. I have this code;
#include <iostream>
using namespace std;
int x(int);
char * y(char *);
int main() {
x(5);
y("hello");
int (*p) (int); //pointer to function x
char * (*q) (char *); //pointer to function y
p = &x; //holds the address of function x
q = &y; //holds the address of function y
cout << p << endl;
cout << q;
return 0;
}
int x(int a) {
return (a * a);
}
char * y(char *b) {
return (b);
}
So is there a way i can force the cpu to execute a particular function before another using the function addresses?
Upon compiling, the program prints out both addresses as 1
. I was expecting hexadecimal values like that of data items. even when I print the dereferenced values, I still get 1
, what is going on?
Also, if both function addresses are 1
, how does the cpu know which function to execute first?
EDIT:
one of my questions is left unanswered, which i find very important! Doesn't wholly make it a duplicate even though some are.