Hi all, why does this work? the function type i wrote is int, but i have a string in the argument area? Sorry for the Noob question.. Can you help me understand a bit better?
// EduFunction_Class.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
usingnamespace std;
int display_int(int numbr, string chr) // You can transfer both int and Char in one Function and more.
//Despite the fact that string is in the int display_int function
{
//Multiple arguments can be created here......
cout << endl << numbr; // only use what is in the funtion unless you need to calculate here.
cout << endl << chr; // only add to the string using another string variable if you wish to extend.
cout << endl;
return 0; // can i return this to main?? "Use another funtion to explore...?"
}
int main()
{
int number = 15;
string cr = "99 Clearly numbers can be strings too!";
display_int(number,cr); // see funtion for output display.
cin.ignore(); // doesn't allow any key to end an app though...
//system("pause"); // cheat for pause.
return 0;
}
Hi all, why does this work? the function type i wrote is int, but i have a string in the argument area? Sorry for the Noob question.. Can you help me understand a bit better?
The function type tells you what kind of value the function returns.
That is completely unrelated to the types of the arguments the function takes.
Here's an example to help you visualize a common pattern of returning a status: 'true' if a function call succeeds or 'false' if it fails.
Since functions return one thing, if you'd like both a status and function-related output, use outgoing parameters. In C++ these are typically references (but could also be pointers). [ Related but not shown here: to denote that a reference will be read-only and not modified, add the keyword const ]