Pointers
Pointers
A pointer variable stores the address of another object.
Pointers
pointers.cpp
#include <iostream>
int main() {
int first = ;
int second = ;
int* current = &first;
std::cout << "current=" << *current << std::endl;
current = &second;
std::cout << "current=" << *current << std::endl;
std::cout << "first=" << first << std::endl;
std::cout << "second=" << second << std::endl;
return 0;
}
#include <iostream>
int main() {
int first = ;
int second = ;
int* current = &first;
std::cout << "current=" << *current << std::endl;
current = &second;
std::cout << "current=" << *current << std::endl;
std::cout << "first=" << first << std::endl;
std::cout << "second=" << second << std::endl;
return 0;
}
#include <iostream>
int main() {
int first = ;
int second = ;
int* current = &first;
std::cout << "current=" << *current << std::endl;
current = &second;
std::cout << "current=" << *current << std::endl;
std::cout << "first=" << first << std::endl;
std::cout << "second=" << second << std::endl;
return 0;
}
#include <iostream>
int main() {
int first = ;
int second = ;
int* current = &first;
std::cout << "current=" << *current << std::endl;
current = &second;
std::cout << "current=" << *current << std::endl;
std::cout << "first=" << first << std::endl;
std::cout << "second=" << second << std::endl;
return 0;
}
#include <iostream>
int main() {
int first = ;
int second = ;
int* current = &first;
std::cout << "current=" << *current << std::endl;
current = &second;
std::cout << "current=" << *current << std::endl;
std::cout << "first=" << first << std::endl;
std::cout << "second=" << second << std::endl;
return 0;
}
#include <iostream>
int main() {
int first = ;
int second = ;
int* current = &first;
std::cout << "current=" << *current << std::endl;
current = &second;
std::cout << "current=" << *current << std::endl;
std::cout << "first=" << first << std::endl;
std::cout << "second=" << second << std::endl;
return 0;
}
#include <iostream>
int main() {
int first = ;
int second = ;
int* current = &first;
std::cout << "current=" << *current << std::endl;
current = &second;
std::cout << "current=" << *current << std::endl;
std::cout << "first=" << first << std::endl;
std::cout << "second=" << second << std::endl;
return 0;
}
#include <iostream>
int main() {
int first = ;
int second = ;
int* current = &first;
std::cout << "current=" << *current << std::endl;
current = &second;
std::cout << "current=" << *current << std::endl;
std::cout << "first=" << first << std::endl;
std::cout << "second=" << second << std::endl;
return 0;
}
#include <iostream>
int main() {
int first = ;
int second = ;
int* current = &first;
std::cout << "current=" << *current << std::endl;
current = &second;
std::cout << "current=" << *current << std::endl;
std::cout << "first=" << first << std::endl;
std::cout << "second=" << second << std::endl;
return 0;
}
pointer variable
A pointer type uses `*` in its declaration, such as `int*`.