Answers for "c++ making function pointer"

C++
3

Function pointer C++

void one() { cout << "Onen"; }
void two() { cout << "Twon"; }


int main()
{
	void (*fptr)(); //Declare a function pointer to voids with no params

	fptr = &one; //fptr -> one
	*fptr(); //=> one()

	fptr = &two; //fptr -> two
	*fptr(); //=> two()

	return 0;
}
Posted by: Guest on July-30-2020
1

pointers in c++

void simple_pointer_examples() {
    int   a;  // a can contain an integer
	int*  x;  // x can contain the memory address of an integer. 
 	char* y;  // y can contain the memory address of a char. 
 	Foo*  z;  // z can contain the memory address of a Foo object.  
 
    a = 10;
    x = &a;   // '&a' extracts address of a 
  
    std::cout <<  x << std::endl; // memory address of a => 0x7ffe9e25bffc
    std::cout << *x << std::endl; //          value of a => 10
}
Posted by: Guest on July-15-2021

Browse Popular Code Answers by Language