top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How can I create my own functions in C++?

+1 vote
70 views
How can I create my own functions in C++?
posted Dec 4, 2014 by Amit Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

If you want to create you function in main(), then there is no difference for creating function in C or C++; Now, if you want to create your function in class, (c++)

#include<iostream.h>
class sample
{       
    public:
        int a,b;
        int sum(int x,int y)
        {
        return x+y;
        }
};

main()
{
  sample o1;
  int result;
  o1.a=10;
  o1.y=20;
  result = o1.sum(a,b);
  cout << "sum = " << result;    
}
answer Dec 5, 2014 by Chirag Gangdev
Similar Questions
+1 vote

I want to build my own library in C, can someone help me with this?

+2 votes

Is it possible like

struct Point
{
int X;
int Y;
void Display() { cout << " string"; }
};
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...