Adrian G. answered 06/12/19
High School / College Programming Tutor - Full-Time Software Engineer
You can declare a variable without defining it in the same line. For instance:
int x; //this is a "declaration" of a new integer "x".
x = 9; //defines this variable x to have a value of 9.
You can also declare a function without defining it. You can do this by declaring functions at the top of a single-file program so that the compiler does not give compilation errors and then you define the function later. Also, for programs with multiple files you normally have a header file where your function declarations are and then you define these functions in a different file.
Here is an example of the first scenario:
int foo(int a, int b); // this is the function declaration for "foo'
int main() {
//Some code calling foo(...);
}
int foo(int a, int b) { //this begins the function definition for the function "foo"
a++;
b++;
return a + b;
}
I hope this helps