Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 22484

How to run multiple functions in one file (C++)

$
0
0

So this seems to be a frequently asked question but on more complex problems. I am just starting out and am coming from a higher level language (python) and thus a bit confused as to what C++ wishes me to specify. I have 2 virtually identical functions and when I run the file it seems to just output one of them and I am not sure why not both. It seems to be something with the naming. C++ seems to want to prefer things named as main(). I feel for someone with experience this may be quite obvious and I would be thrilled to also have some more details about the goings on of C++ and how/why it determines what functions to "prefer". (I am using a VScode environment)

#include <iostream>using namespace std;int starter(){    //declaring variables    int a, b;    int result;    // process    a = 5;    b = 2;    a = a + 1;    result = a - b;    //print the result    cout << result;    //terminate the program    return 0;}int main(){    int a = 5; //"c-like"    int b (3); // "constructor"    int c {1}; // "uniform"    int result; //initial value undetermined    result = a + b - c;    cout << result;    return 0;}

only the "main(){}" block of code is executed


Viewing all articles
Browse latest Browse all 22484

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>