IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
C++
Search C++ Group:

Advanced
-Collapse +Expand C++ To/From
To/FromCODEGuides
-Collapse +Expand C++ Study Test
PRESTWOODCERTIFIED
-Collapse +Expand C++ Store
PRESTWOODSTORE

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingC++Standard C++C++ Language...   Print This     
  From the January 2016 Issue of Prestwood eMag
 
C++ Language Basics:
C++ Custom Routines
 
Posted 16 years ago on 11/16/2008 and updated 12/25/2008
C++ Code Snippet:
 A flashcard from our C++ Flashcards Library
 A code snippet from our C++ Code Snippets Page

KB101632

Languages Focus: Custom Routines

For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.

C++ Custom Routines

C++ is a hybrid language and as such offers global functions and class methods. A function must come before it's usage or you can prototype the function.

Syntax Example:
void sayHello(string pName) {
cout << "Hello " + pName + "\n";
};
 
int add(int p1, int p2) {
int result;
 
  result = p1 + p2;
return result;
};

Prototyping

The following is the complete C++ source code for a simple console application that demonstrates prototyping.

You either have to define your custom routines above main() so that they can be used within main() or prototype them. C++ allows you to prototype custom routines so that you can put their implementation below main.

#include "stdafx.h"
#include <iostream>
#include <string>
 
using namespace std;
//
//Prototypes
//
void sayHello(string pName);
int add(int p1, int p2);
 
//
//Main.
//
void main()
{
sayHello("Mike");
cout << "2+2=" << add(2,2) << "\n";
}
 
//
//Implementation section.
//
void sayHello(string pName) {
cout << "Hello " + pName + "\n";
}
 
int add(int p1, int p2) {
int result;
  result = p1 + p2;
return result;
}

More Info


Comments

1 Comments.
Share a thought or comment...
Comment 1 of 1

This language is really interesting. The language is the basis of many frameworks and modern languages used in companies nowadays. Many Graduate cv writers in resume companies and organizations are skilled in C++ and Python languages and frameworks. 

Posted 34 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P177A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101632 Counter
16569
Since 11/16/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]