Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6065149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:21:31+00:00 2026-05-23T09:21:31+00:00

This is a small program : #include <iostream> using namespace std; int main() {

  • 0

This is a small program :

#include <iostream>
using namespace std;

int main() {
    f();
    system("pause");
}

void f() {
    static int x = 20 ;
    class tester {
    public :
        tester() {
            cout << x ;
        }
    } x1;
}

The error that i get here is :error C3861: ‘f’: identifier not found

If i place the function f above main I will get the desired output.

Why it is so ?
I was told that program execution begins at main. According to this the code should run in the first case also.

How does the compiler start reading the program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:21:31+00:00Added an answer on May 23, 2026 at 9:21 am

    The beginning of the compilation and the beginning of the execution of the program are two different things.

    The execution starts from the main.

    The compilation begins from the beginning of the file; the compiler don’t “jump around” the file to find the needed pieces, but it reads the input in a linear fashion (I suspect that this related, among the other things, to the fact that the C++ grammar is really complicated).

    When the compiler is at some point in parsing the file, it only knows what has been declared/defined up to that point1.

    Because of this, function prototypes (and non-defining declarations in general) have been invented: the prototypes of all the functions defined in the file are put at the beginning of the file, typically after the #include directives or in a separated include file. The prototypes tell to the compiler that such functions will be defined later, and what is the function signature (i.e. name, parameters, return value).

    The prototype is made as a normal function, but without the body, which is replaced by a semicolon2. For example, in your code you would write

    void f();
    

    before the main.


    1. IIRC there are some relaxations to this rule that allow the compiler to “wait” for some declarations to make some template magic work, but this is not relevant here.

    2. In a prototype is also common not to write the names of the parameters, leaving just their type (this can be done also in function definitions, but it doesn’t make much sense there unless you have a formal parameter you don’t use). Still, I prefer to leave the parameter names there as a form of documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a small test program I wrote: #include <iostream> using namespace std; class A
header.h #include <iostream> #include <vector> class CombatLine{ std::stringstream Line; std::vector<std::string> TokenLine; void SetLine(std::string s){
Okay, I got this small program which tags (as in ID3v2.4 etc.) some music
As I stated in this question , I am using SDL for a small
I have a small program I want to execute to test something #include <map>
I have this small program that reads a line of input & prints the
I've got this small question - given a bitmask of weekdays (e.g., Sunday =
I have this small code library that I'm considering releasing into Open Source. I
Let's say I have a line of text like this Small 0.0..20.0 0.00 1.49
Here is the situation. This small company I'm working with wants to have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.