---
title: "How to create friend function in c  ?"  
description: "How to create friend function in c  ?"  
author: "marcel ethan"  
published: 2013-06-14  
updated: 2013-06-15  
canonical: https://www.mindstick.com/forum/1117/how-to-create-friend-function-in-c  
category: "visual c++"  
tags: ["visual c++"]  
reading_time: 1 minute  

---

# How to create friend function in c  ?

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances),\
How to create [friend function](https://answers.mindstick.com/qa/92532/what-is-a-friend-function) in [c++](https://www.mindstick.com/blog/745/array-in-c-plus-plus)?\
Thanks in advance.

## Replies

### Reply by AVADHESH PATEL

you can create friend [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) from follow syntexfriend type function_name(classname object);you can try following example of friend function\

```
class myclass{int n,d;public:myclass(int i,int j){ n = i; d = j;}//declare a friend of myclassfriend int isfactor(myclass ob);};int isfactor(myclass ob){ if(!(ob.n % ob.d)) return 1;else return 0;}int main( ){myclass ob1(10,2),ob2(13,3);if(isfactor(ob1)) cout<<"2 is a factor of 10\n";else cout <<"2 is not a factor of 10\n";if(isfactor(ob2) cout<<"3 is a factor of 13\n";else cout<<"3 is not a factor of 13\n";return 0;}
```


---

Original Source: https://www.mindstick.com/forum/1117/how-to-create-friend-function-in-c

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
