why is a void
written after static keyword
in a function definition?
I tried writing a void before static keyword.
It's giving me an error and displaying a message.
volatile is expecte
why is a void
written after static keyword
in a function definition?
I tried writing a void before static keyword.
It's giving me an error and displaying a message.
volatile is expecte
I assume you are referring to C or C++, so that is simply the startard that defines it, and it makes an easier life to the people who write the parser for the compiler (they don't have to guess the order of keywords).
In relation to using the languages as a programer: void
refers to the return type of the function and is a part of the function declaration just like its name and parameters. The static
keyword says different things in each language. In a nutshell, in C it means that the function is visible only in that file, in C++ (and Java) is says that the function does not need the this
and can be called on the Class itself (without an instance). For more info in this issue read this question
See,it's a standard in any language where static
tells that this function can be accessed from anywhere and void
tells that this function is not returning anything and also as void
is a return type and return type is always written just before function name therefore, you cant put static
in between,you have to write it before.i hope you understand
void
is a keyword for defining the method's return type. In the case of void
it's simply saying the method won't return anything. You can put other things (int
, String
, etc.) there, but they have to reflect what you want to return (and you should get an error if you have code paths that won't return).
The reason void
needs to be after static
is because that's what the language defines. The return type comes before the method's name. You're getting an error because you're defining the method in a way the compiler isn't expecting.