B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP C++ Functions | Login Technologies

C++ Functions

User-defined Functions: Functions in C++ are blocks of reusable code used to perform a specific task. They help organize logic and reduce repetition.

यूज़र-डिफाइंड फंक्शन्स: C++ में फंक्शन कोड का एक अंश है जो कार्य को कार्यक्रम करता है और कोड को संगठित करता है।

1. void sum() - No parameters, no return
#include <iostream>
using namespace std;

void sum() {
  int a = 5, b = 10;
  cout << "Sum = " << a + b << endl;
}

int main() {
  sum();
  return 0;
}

Output: Sum = 15

Explanation: Function prints sum of two numbers. No inputs, no return.

व्याख्या: फंक्शन दो आंको जोड़ का योग प्रिंट करता है। कोई इनपुट नहीं, कोई रिटर्न नहीं।


2. void sum(int a, int b) - Parameters, no return
#include <iostream>
using namespace std;

void sum(int a, int b) {
  cout << "Sum = " << a + b << endl;
}

int main() {
  sum(7, 8);
  return 0;
}

Output: Sum = 15

Explanation: Function takes parameters and prints the result.

व्याख्या: फंक्शन पैरामीटर लेता है और योग प्राप्त करता है।