YourPets.cpp
TCP1, p. 146
download
#include <iostream>
using std::cout;
using std::endl;
int dog, cat, bird, fish; // global vars initialized to 0
int main(); // can be declared before its definition
void f(int pet); // defined after main()
void g(void){} // defined before main()
int main()
{
int i, j, k;
cout << "sizeof(int): " << sizeof(int) << endl;
cout << "f():\t" << (long)&f << endl;
cout << "g():\t" << (long)&g << endl;
cout << "dog:\t" << (long)&dog << endl;
cout << "cat:\t" << (long)&cat << endl;
cout << "bird:\t" << (long)&bird << endl;
cout << "fish:\t" << (long)&fish << endl;
cout << "main():\t" << (long)&main << endl;
cout << "i:\t" << (long)&i << endl;
cout << "j:\t" << (long)&j << endl;
cout << "k:\t" << (long)&k << endl;
f(dog), f(cat), f(bird), f(fish), g(); // multiple function calls on one line
return 0;
}
void f(int pet)
{
cout << "pet id number: " << pet << endl;
}
/*
g++ YourPets.cpp -o YourPets
./YourPets
sizeof(int): 4
f(): 94641376949411 // f() defined after main()
g(): 94641376948745 // g() defined before main()
dog: 94641376960852
cat: 94641376960856
bird: 94641376960860
fish: 94641376960864
main(): 94641376948756 // after g(), before f()
i: 140721441130380
j: 140721441130384
k: 140721441130388
pet id number: 0 // f(dog)
pet id number: 0 // f(cat)
pet id number: 0 // f(bird)
pet id number: 0 // f(fish)
*/
Comments
Post a Comment