Basic Function Name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <conio>

void printmessage ();

int main()
{
	printmessage();
   getch();
   return 0;
}

void printmessage()
{
	cout<<"I'm a function!";
}


Can I know the following answer?
1. Function Call
2. Function header
3. Function declaration in the program

And why need to use void? What different with int?

Thanks...
Last edited on
what do you want to know from the first 3 things ?

and you have to use void because the function returns nothing.
if you return an integer you should write int.
Function call is the expression

printmessage();

There is no such termnin in the C/C++ as "function header".

And you have two function declarations in your program the second of them is also a definition.

First declaration:

void printmessage ();

Second declaration and simultaneously definition:


1
2
3
4
void printmessage()
{
	cout<<"I'm a function!";
}


You may rewrite your prograqm the following way

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <conio.h>

using namespace std;

void printmessage()
{
	cout<<"I'm a function!\n";
}

int main()
{
   printmessage();

   getch();

   return 0;
}

@gelatine
I wanted to know each of the 3 answer for the code above...

if you return an integer you should write int.

What u mean by "return"? Is that all the program related to number must use a int instead of void? But why line 6 use int main() since it also don't play with value? TQ...

@vlad from moscow
Thanks for the 1 and 3 and a modified arrangement, actually that's a simple program I got from C++ book, but then it ask for that 3 answer...so I think there should have answer for 2 is it? TQ...
Last edited on
Topic archived. No new replies allowed.