0% found this document useful (0 votes)
152 views

Poi Nter Si MPL e

The document discusses pointers in C++. It defines some integer variables, assigns memory addresses to pointers to store the integer values, and prints out the values stored in the variables and their memory addresses using pointers. It also demonstrates pointers to pointers by defining a pointer that stores the memory address of another pointer.

Uploaded by

ayesite
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Poi Nter Si MPL e

The document discusses pointers in C++. It defines some integer variables, assigns memory addresses to pointers to store the integer values, and prints out the values stored in the variables and their memory addresses using pointers. It also demonstrates pointers to pointers by defining a pointer that stores the memory address of another pointer.

Uploaded by

ayesite
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Poi nter si mpl e

#include <stdio>
#include <conio>
#include <iostream>
main ()
{
int satu;
int *lokasi,value;
satu=5;
lokasi=&satu;
value=*lokasi;
cout << "satu = " << satu << endl;
cout << "lokasi = " << lokasi <<
endl;
cout << "value = " << value << endl;
getch();
}
andy = 25;
fred = andy;
ted = &andy;
andy = 25;
fred = andy;
ted = &andy;
beth = *ted;
char a;
char * b;
char ** c;
a = 'z';
b = &a;
c = &b;

c has type char** and a value of 8092


*c has type char* and a value of 7230
**c has type char and a value of 'z'
#include <stdio>
Poi nter #include <conio>
#include <iostream>
to bates()
{cout<<"================================"<<endl;}
Poi nter main ()
{
int satu;
int *lokasi,value;
//pointer ke pointer
int ** value2;
satu=5;
lokasi=&satu;
//pointer ke pointer
value2=&lokasi;
value=*lokasi;
cout << "satu = " << satu << endl;
cout << "lokasi = " << lokasi << endl;
cout << "value = " << value << endl;bates();
//hasil pointer ke pointer
cout << "value pointer *= " << *value2 << endl;
cout << "value pointer **= " << **value2 << endl;
getch();
}
Dekl arasi Functi on
Prot otype
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
//nama function
hitungvolume(float jari);
hitungluas(float jari);
main()
{
float kerucut_l,kerucut_v;
int jari;
clrscr();
cout<<"Masukan Jari = ";cin>>jari;
//panggil function
kerucut_v=hitungvolume(jari);
kerucut_l=hitungluas(jari);
cout<<"Volume Kerucut = "<<kerucut_v<<endl;
cout<<"Luas Kerucut = "<<kerucut_l<<endl;
getch();
}
//isi function
//rumus volume kerucut
hitungvolume(float jari){
int tinggi;
const float phi=3.14;
cout<<"Masukan Tinggi = ";cin>>tinggi;
return(phi*jari*jari*tinggi*0.33);}
//rumus luas kerucut
hitungluas(float jari){
int t;
cout<<"Masukan T = ";cin>>t;
return(3.14*jari*jari*t);}
Functi on gl obal n l okal
Global or
eksternal

Lokal or
internal

Statement
Functi on gl obal n l okal
n val ue in function
#include <stdio> //Statement global
#include <conio> cout << "The begin = " << z << '\n';
#include <iostream> x=10,y=3;
int kurang(int a, int b=8) z = kurang(7,2);
{ cout << "The first = " << z << '\n';
int r; cout << "The second = " << kurang (x,y) << '\n';
r=a-b; cout << "The third = " << kurang (5,4) << '\n';
return (r); z= 9 + kurang(x,y);
} cout << "The fourth = " << z << '\n';
//deklarasi global getch();
int x,y,z=9; }
main ()
{
Functi on b y Val ue n Ref erence
#include <stdio>
#include <conio>
#include <iostream>
// by value or satu arah
//tidak ada nilainya
perkalian_value (int a, int b, int c)
{
a*=2;
b*=2;
c*=2;
}

//by reference or dua arah


//bolak balik(ada nilainya)
perkalian_reference (int& a, int& b, int& c)
{
a*=2;
b*=2;
c*=2;
}
main ()
{
int x=1, y=3, z=7;
cout<<endl<<endl;
//by value
perkalian_value(x, y, z);
cout << "x=" << x << ", y=" << y << ", z=" << z;
cout<<endl<<endl;
//by reference
perkalian_reference (x, y, z);
cout << "x=" << x << ", y=" << y << ", z=" << z;
getch();
}
Functi on #include <stdio>
Overl oad #include <conio>
#include <iostream>
int itung (int a, int b)
{
return (a*b);
}

float itung (float a, float b)


{
return (a/b);
}

int main ()
{
int x=5,y=2;
float n=8.8,m=1.1;
cout << " "<<itung (x,y);
cout << "\n";
cout << " "<<itung (n,m);
cout << "\n";
getch();
}
Tugas Searching I nl ine Fun cti on

 Tidak bol eh sama dengan


modul

 Cari Source c od e nya

 Jelaskan teori nya / Mahasi swa

 Kirim ke
tugasaye@gmai l.co m

You might also like