c++ pointers and functions
#include <iostream> using namespace std; void increment(int *n){ //declare argument of the functon as pointer *n+=1; cout<<"In function: "<<*n<<endl; } int main() { int x=5; increment(&x); //passing the address of the variable to the function cout<<"In main: "<<x<<endl; }
pointers in c++
#include <iostream> using namespace std; int main() { int x=5; int *ptr=&x; cout<<&x<<endl; //prints the address of the variable (x) cout<<ptr<<endl; //prints the address of the variable (x) cout<<*ptr<<endl; //prints the value of x(5) cout<<&ptr<<endl; //prints the address of the pointer (ptr) }
c++ fonksion pointer
#include <stdio.h> int f1(int x) { return x * 2; } int f2(int x) { return x * 4; } int main() { int (*fptr1)(int) = &f1; fptr1 = &f2; fptr1(3); }
Source: necatiergin2019.medium.com
Pointers in c++
int x = 2; int *y = &x; cout << *y;
C/C++ Pointers
int* pc, c; c = 5; pc = &c; c = 1; printf("%d", c); // Output: 1 printf("%d", *pc); // Ouptut: 1
Source: www.programiz.com