Newb function question.

Hey everyone!

I am quite new to c++ and programming in general, so this will be a newbie question.

I am going through the tutorial provided by the cpp website and currently reading the function section.

My issue is this (>.<). I don't understand how the following code doesn't give an error because isn't "I'm a function!" a string value?
So when the function printmsg() is called shouldn't it create an error because it is void (no value)?

I'm guessing it is because it is calling a stream?

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

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

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


Thank you!

The "I'm a function!" part of that function is a string literal and is perfectly valid.

The void keyword dictates that the string won't return a value. Again, your function would be perfectly valid as it is.

It would be invalid if you specified it was returning something and it didn't or you tried to return something in a void function.
I see, thank you :)! Now looking at the by reference section this makes alot more sense.
Topic archived. No new replies allowed.