Pass by Reference Vs Pass by Pointer
Pass by Reference Vs Pass by Pointer
ិ Pass by Pointer
Difference Pass By Reference Pass by Pointer
Syntax and - បងរកើតងោយង្ប្ើ ាស់ & មុខ Parameter - ង្ប្ើ ាស់ Pointer(*) មុខ Parameter
Declaration - ង្បើ្ាស់ *(Dereference) ង ើមបកើ ែក្បតំលៃែនុរ Function
Pass - Pass variable directly - ង្ប្ើ ាស់ &(Address of) ងេៃងៅ
Use - មិន្តូវការ្រប់្ររ Pointer - ្តូវការ្រប់្ររ Pointer
- Syntax ្សង ៀរ Pass by value o &(Address of): ចំៃរ Memory Address of Variable
- បុកនែវាក្ប្បួៃតំលៃែនុរ Function o *(Dereference): Access ងៅកាន់តំលៃរបស់ Memory
Address របស់ Variable
Memory Acces - Operate ងៅងៃើ Original Variable ងោយគ្មាន្តូវការ - Operate ងៅងៃើ Memory Address របស់ Variable ងោយង្បើ
រណនា Memory Address *(Dereference) ង ើមបកើ ែក្បតំលៃ
Nullability - មិនអាច null(្តូវកតមាន Object or Variable) - អាចមាន null or nullptr
Use Case - ចរ់កែក្បតំលៃែនុរ Function ងោយមន
ិ ង្ប្ើ ាស់ - ង្ប្ើ ាស់ Dynamic Memory
Pointer - null pointer(ទងទ)
- សំរាប់ Object or Variable ំៗងោយគ្មានការ Copy
Syntax - Create return-type func-name(data-type &par){ return-type func-name(data-type *par){
Statements; *par = value;
} }
Syntax - Calling int main(){ int main(){
func-name(variable); func-name(&variable);
} }
ង្បៀបង ៀបរវារ Pass By Reference និរ Pass By Pointer