Fonksiyon Örneği
#include <iostream>
#include <string>
using namespace std;
int f(int *p) {
if(*p==-1)
return 0;
int i=p[0]+f(p+1);
cout<<i<<" ";
return i; }
int main() {
int *i=new int[9]{1,2,3,4,5,-1};
cout<<f(i);
}
Çıktı :
5 9 12 14 15 15
Pointer Örneği
#include <iostream>
#include <string>
using namespace std;
int main() {
class {
public:
char *c;
int x;
string f() {
string s="";
for(int i=0; i<x; i++) {
s+=c[x-i-1];
cout<<s<<endl;
}
return s;
}
}y;
y={"far",3};
cout<<y.f(); }
Çıktı :
r
ra
raf
raf
Pointer Örneği
#include <iostream>
#include <string>
using namespace std;
int main() {
char* c="test";
for(int i=0; i<4; i++)
{
string s(i,' ');
cout<<s<<(c+i)<<endl; }
}
Çıktı :
test
est
st
t
Pointer Örneği
#include <iostream>
#include <string>
using namespace std;
int main() {
union U{
char* p1;
char* p2; };
U u;
u.p1="test";
for(int i=0; i<4; i++) {
cout<<u.p1<<endl;
u.p2++; }
}
Çıktı :
test
est
st
t
Bu yazı yorumlara kapalı.