Zaki Mirza’s Blog

Icon

… About software and beyond!

Quick C++ Quiz #1


Im starting a little section for C++ quizes. Im nowhere near a C++ wizard. Just something i learn from here and there and ill put em up as food for thought for all my readers. Part 2 ready as well lets c.

consider this :

//quiz.cpp

 int main(int argc, char** argv){
int a();
}

Whats the problem with above code if any. Also, what do you think the above code does (or tries to do?) what is ‘a’?

Filed under: C++, programming, quiz

7 Responses

  1. Samer says:

    it will give u no errors ur simply defining a function a whoz return type is an integer :S that wat i kno atleast

  2. Nirmal says:

    i suspect it gets inlined

  3. Mebrahtu says:

    Fist the function main doesn’t return an integer (just being technical), second you are trying to declare a function inside the main function wit the code int a(). If the code is just like the way it is it will not give any compile or run time error. But if you try to put some code inside a() function then that is where the problem begins.

    Nice bit of quiz though!

  4. OpenAsthra says:

    Yes, I agree with Mebrathu.

  5. crabs says:

    What?!
    1. main returns int in standard c++. many compilers/systems support deviations, but they are, by no means, good code.
    2. you can’t declare a function inside another function! code or not, it must be before the execution of main in the global namespace, inside a class, or inside another namespace.
    3. the only functions that get inlined are (by most compiler’s standards) ones that are defined within a class rather than from a global scope, or ones that are declared inline. other compilers may contain support for auto-inlining short functions.

  6. koti says:

    I think this will not show any run time or compile time errors. but i tried to put some code inside a() , i got error i didn’t understand why it happened ….

  7. yusuf maxamed says:

    iam new student i like to learn programming language so help me please

Leave a reply to crabs Cancel reply

RSS Google Shared Items

  • An error has occurred; the feed is probably down. Try again later.

RSS Google Reader Starred Items

  • An error has occurred; the feed is probably down. Try again later.

Top Clicks

  • None