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
it will give u no errors ur simply defining a function a whoz return type is an integer :S that wat i kno atleast
i suspect it gets inlined
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!
Yes, I agree with Mebrathu.
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.
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 ….
iam new student i like to learn programming language so help me please