Basic question

0 Shantanu Odak · December 29, 2014
/images/forum/upload/2014-12-29/9507c362b7a03202b59f7c53ea410c7a.png

Post a Reply

Replies

Oldest  Newest  Rating
0 Abdullah Karaman · December 30, 2014
What you did is right. You declare your function which is above your main. And under your main you define it. 
0 Shantanu Odak · December 29, 2014
thank you!! its was totally understandable!!:-) @Franz
+3 Franz Schmidt · December 29, 2014
The function in line 4 is called a prototype.
You basically call a function like in the main

And in line 12 you don't need to make one, because you declair a function (this visible on the curly brackets in line 13 and 15.
You also type a semicolen in line 6 after the main(). This also is the declairation of the function.

Don't know if you know the usage of a prototype but her a little example where you use it:

#include <iostream>
using namespace std;

void func_1(){
  cout << "This is function 1. It calls function 2.";
  func_2();
}
void func_2(){
  cout << "This is function 2. It calls function 1.";
  func_1();
}

int main(){
  cout << "This is the main function. It calls function 1.";
  func_1();
  cout << "End.";
  return 0;
}

This is a endless programm, but it won't work because you call function 2 in function 1 before it got declaired.

So you use prototypes to drag the function to the beginning of the programm:

#include <iostream>
using namespace std;

//Protoypes
void func_1(void);
void func_2(void);

void func_1(){
  cout << "This is function 1. It calls function 2.";
  func_2();
}
void func_2(){
  cout << "This is function 2. It calls function 1.";
  func_1();
}

int main(){
  cout << "This is the main function. It calls function 1.";
  func_1();
  cout << "End.";
  return 0;
}

After the protoypes every function is declaired and can be called after it at any time.

You also used it in the right way in your example.
You wrote the deployprogram function under the main function.
And if you don't use prototypes the main thinks the deployprogram function doesn't exist.

Can look up for more here

Hope it was understandable :D
  • 1

C++

107,194 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator