A semicolon (';') is not needed after a function declaration. C++What are the differences between a pointer...
Fired for using Stack Exchange. What did I do wrong?
Why would you use 2 alternate layout buttons instead of 1, when only one can be selected at once
How many copper coins fit inside a cubic foot?
What caused Doctor Strange to repent of his selfishness and become Earth's protector?
Can I legally make a website about boycotting a certain company?
multiple null checks in Java8
Why is quixotic not Quixotic (a proper adjective)?
Why do we divide Permutations to get to Combinations?
Found a major flaw in paper from home university – to which I would like to return
Can "ee" appear in Latin?
Short story where Earth is given a racist governor who likes species of a certain color
Was Opportunity's last message to Earth "My battery is low and it's getting dark"?
Failing PhD, how to go forward?
Ramanujan's radical and how we define an infinite nested radical
Can I use a larger HVAC Hard Start kit than is recommended?
Why is Shelob considered evil?
Relation between roots and coefficients - manipulation of identities
Taking an academic pseudonym?
Why do BLDC motor (1 kW) controllers have so many MOSFETs?
How can I portray body horror and still be sensitive to people with disabilities?
How does the income of your target audience matter for logo design?
How can a kingdom keep the secret of a missing monarch from the public?
Run a command that requires sudo after a time has passed
Is Screenshot Time-tracking Common?
A semicolon (';') is not needed after a function declaration. C++
What are the differences between a pointer variable and a reference variable in C++?How do you declare an interface in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListWhat is the effect of extern “C” in C++?What is the “-->” operator in C++?Why do we need virtual functions in C++?Easiest way to convert int to string in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why is reading lines from stdin much slower in C++ than Python?
I just recently took an intermediate programming test, and one of the questions I got wrong was as follows:
A semicolon (';') is not needed after a function declaration.
True or False.
I chose "false" (and please correct me if I'm wrong because I feel like I'm going crazy), a function declaration is what you write before the definition (at the top of the code) so the compiler knows the function call before even calling it, and a function definition is what makes up the function as a whole.
ie.
Declaration:
int func();
Definition:
int func() {
return 1;
}
My question is, shouldn't the answer to this be false?
c++
New contributor
Logan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 10 more comments
I just recently took an intermediate programming test, and one of the questions I got wrong was as follows:
A semicolon (';') is not needed after a function declaration.
True or False.
I chose "false" (and please correct me if I'm wrong because I feel like I'm going crazy), a function declaration is what you write before the definition (at the top of the code) so the compiler knows the function call before even calling it, and a function definition is what makes up the function as a whole.
ie.
Declaration:
int func();
Definition:
int func() {
return 1;
}
My question is, shouldn't the answer to this be false?
c++
New contributor
Logan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
18
A definition is also a declaration. But I would say your answer was correct.
– Neil Butterworth
16 hours ago
54
It's a tricky nitpicking question and has no bearing on anyone's ability to program well.
– phonetagger
16 hours ago
16
I always find the questions, that result in double-negatives, confusing. In my mind, such questions are designed to trip students up. Why couldn't the question be formed in a following way: "A semicolon (';') is always needed after a function declaration. True or False."? :/
– Algirdas Preidžius
16 hours ago
6
@phonetagger All this confusion goes to show how badly worded the question is.
– François Andrieux
16 hours ago
14
Hanlon's Razor suggests that the author of the test mixed up "declaration" and "definition".
– Sneftel
16 hours ago
|
show 10 more comments
I just recently took an intermediate programming test, and one of the questions I got wrong was as follows:
A semicolon (';') is not needed after a function declaration.
True or False.
I chose "false" (and please correct me if I'm wrong because I feel like I'm going crazy), a function declaration is what you write before the definition (at the top of the code) so the compiler knows the function call before even calling it, and a function definition is what makes up the function as a whole.
ie.
Declaration:
int func();
Definition:
int func() {
return 1;
}
My question is, shouldn't the answer to this be false?
c++
New contributor
Logan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I just recently took an intermediate programming test, and one of the questions I got wrong was as follows:
A semicolon (';') is not needed after a function declaration.
True or False.
I chose "false" (and please correct me if I'm wrong because I feel like I'm going crazy), a function declaration is what you write before the definition (at the top of the code) so the compiler knows the function call before even calling it, and a function definition is what makes up the function as a whole.
ie.
Declaration:
int func();
Definition:
int func() {
return 1;
}
My question is, shouldn't the answer to this be false?
c++
c++
New contributor
Logan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Logan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 7 hours ago
Peter Mortensen
13.7k1986111
13.7k1986111
New contributor
Logan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 16 hours ago
LoganLogan
14815
14815
New contributor
Logan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Logan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Logan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
18
A definition is also a declaration. But I would say your answer was correct.
– Neil Butterworth
16 hours ago
54
It's a tricky nitpicking question and has no bearing on anyone's ability to program well.
– phonetagger
16 hours ago
16
I always find the questions, that result in double-negatives, confusing. In my mind, such questions are designed to trip students up. Why couldn't the question be formed in a following way: "A semicolon (';') is always needed after a function declaration. True or False."? :/
– Algirdas Preidžius
16 hours ago
6
@phonetagger All this confusion goes to show how badly worded the question is.
– François Andrieux
16 hours ago
14
Hanlon's Razor suggests that the author of the test mixed up "declaration" and "definition".
– Sneftel
16 hours ago
|
show 10 more comments
18
A definition is also a declaration. But I would say your answer was correct.
– Neil Butterworth
16 hours ago
54
It's a tricky nitpicking question and has no bearing on anyone's ability to program well.
– phonetagger
16 hours ago
16
I always find the questions, that result in double-negatives, confusing. In my mind, such questions are designed to trip students up. Why couldn't the question be formed in a following way: "A semicolon (';') is always needed after a function declaration. True or False."? :/
– Algirdas Preidžius
16 hours ago
6
@phonetagger All this confusion goes to show how badly worded the question is.
– François Andrieux
16 hours ago
14
Hanlon's Razor suggests that the author of the test mixed up "declaration" and "definition".
– Sneftel
16 hours ago
18
18
A definition is also a declaration. But I would say your answer was correct.
– Neil Butterworth
16 hours ago
A definition is also a declaration. But I would say your answer was correct.
– Neil Butterworth
16 hours ago
54
54
It's a tricky nitpicking question and has no bearing on anyone's ability to program well.
– phonetagger
16 hours ago
It's a tricky nitpicking question and has no bearing on anyone's ability to program well.
– phonetagger
16 hours ago
16
16
I always find the questions, that result in double-negatives, confusing. In my mind, such questions are designed to trip students up. Why couldn't the question be formed in a following way: "A semicolon (';') is always needed after a function declaration. True or False."? :/
– Algirdas Preidžius
16 hours ago
I always find the questions, that result in double-negatives, confusing. In my mind, such questions are designed to trip students up. Why couldn't the question be formed in a following way: "A semicolon (';') is always needed after a function declaration. True or False."? :/
– Algirdas Preidžius
16 hours ago
6
6
@phonetagger All this confusion goes to show how badly worded the question is.
– François Andrieux
16 hours ago
@phonetagger All this confusion goes to show how badly worded the question is.
– François Andrieux
16 hours ago
14
14
Hanlon's Razor suggests that the author of the test mixed up "declaration" and "definition".
– Sneftel
16 hours ago
Hanlon's Razor suggests that the author of the test mixed up "declaration" and "definition".
– Sneftel
16 hours ago
|
show 10 more comments
5 Answers
5
active
oldest
votes
You can have a situation where you declare and define the function in one step, i.e. if you include the function definition at the point where you're declaring it. So technically I suppose true is correct. But the question is worded in such a way that I would have answered it the way you did.
add a comment |
In addition to the "a definition is also a declaration" thing, the following is legal C++:
int f(), g();
This declares two functions,f and g, both without arguments and with a return type of int, but the definition of f is not followed (immediately) by a semicolon. Likewise, this is legal:
int f(), i = 42;
But it is indeed not allowed to omit the semicolon entirely in these cases, so it would be somewhat surprising if either was taken as an example of a declaration without a following semicolon. In fact, the following is illegal:
void *p, f() {}
Other than a (mere) function declaration, a function definition cannot be combined with any other declaration or definition to the same type-specifier. (If this were legal, it would define both a void *p and a void f() {}.)
In any case, this seems to be a "gotcha" type of question that should not be in an intermediate programming test.
(Oh, by the way, please don't actually write code like int f(), i = 42;.)
add a comment |
The other answers and comments call out several of the many ways that this is a horrid, misleading and badly-written question. But there is another problem that no one else has identified yet. The question is:
A semicolon (';') is not needed after a function declaration. True or False.
OK, let's look at a function declaration:
int func(); /* */
/* ^ */
/* | */
/* That whitespace is "after the function declaration". */
That whole thing is the declaration. The declaration is not int func() and then followed by a ;. The declaration is int func(); and then is followed by whitespace.
So, the question is: is a semicolon needed after the declaration? Of course not. The declaration already has a semicolon in it which terminated it. A semicolon after the declaration would be pointless. By contrast, int func(); ; would be a semicolon after a function declaration.
The question was almost certainly intended to ask the question "true or false: the last token in a function declaration is always a semicolon" But that's not the question that they wrote, because the author of the quiz was not thinking clearly about the problem.
My advice is to avoid programming language quizzes altogether. They're pretty awful.
Fun fact, while we are on the subject. In C#, these are all legal:
class C {}
class D {};
struct E {}
struct F {};
In C#, a class or struct declaration may end in a semicolon, or not, at your discretion. This odd little feature was added for the benefit of C/C++ programmers coming to C# who have it in their fingertips that type declarations end in a pointless semicolon; the design team didn't want to punish them for having this habit. :-)
3
I would edit the last :-) to ;-)
– Hila DG
8 hours ago
My advice is to avoid programming language quizzes altogether. They're pretty awful.; worth of million upvotes advice!
– haccks
1 hour ago
add a comment |
You can declare a function like this too:
int func(){
return 1;
}
the statement is very ambiguous. The right answer should be: it depends on how you declare the function.
Anyway, I'd have chosen false too, maybe you can report the question to someone.
Anyway, don't put the thing on a personal level. The important thing is that you understood how a function declaration-definition works, so don't worry about it too much, just make sure that the question will be at least checked and go on
– Luca Corsini
16 hours ago
5
Absolutely. Honestly, I learned more about function declaration-definition from getting the question wrong than I would've had I gotten in it correct.
– Logan
16 hours ago
@Logan don't worry too much. If you know how to write and read a function that's all you need. I personally hate these kind of questions that 1. are not well defined 2. test your theoretical knowledge of the syntax. To me it's like muscle memory. When I write each digit goes effortlessly to the key it is supposed to go, but if you give me a test about what keys should a digit press I would be completely hopeless without a keyboard to physically do the action ...
– bolov
13 hours ago
... Writing common syntax (e.g. like a function) will become a second nature to you. And when you will mess it up because you just switched languages, well... intellisense and syntax highlighting make for quick and efficient solutions. Invest your time and energy in something more useful.
– bolov
13 hours ago
add a comment |
This depond on on the condition weather we are declaring or defining the function.
If we declare the the function we need to include semicolon (;) and if we are defining the function semicolon is not needed .
Decleration :
int add(int, int);
Defining the function :
int add(int a, int b)
New contributor
Rocx En Ruff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The problem with this answer is that it suggests that definitions and declaration are mutually exclusive. In fact, every definition is a declaration; definitions are a subset of declarations.
– MSalters
45 mins ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Logan is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54790795%2fa-semicolon-is-not-needed-after-a-function-declaration-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can have a situation where you declare and define the function in one step, i.e. if you include the function definition at the point where you're declaring it. So technically I suppose true is correct. But the question is worded in such a way that I would have answered it the way you did.
add a comment |
You can have a situation where you declare and define the function in one step, i.e. if you include the function definition at the point where you're declaring it. So technically I suppose true is correct. But the question is worded in such a way that I would have answered it the way you did.
add a comment |
You can have a situation where you declare and define the function in one step, i.e. if you include the function definition at the point where you're declaring it. So technically I suppose true is correct. But the question is worded in such a way that I would have answered it the way you did.
You can have a situation where you declare and define the function in one step, i.e. if you include the function definition at the point where you're declaring it. So technically I suppose true is correct. But the question is worded in such a way that I would have answered it the way you did.
edited 16 hours ago
Sneftel
24.3k64279
24.3k64279
answered 16 hours ago
jwismarjwismar
9,50222137
9,50222137
add a comment |
add a comment |
In addition to the "a definition is also a declaration" thing, the following is legal C++:
int f(), g();
This declares two functions,f and g, both without arguments and with a return type of int, but the definition of f is not followed (immediately) by a semicolon. Likewise, this is legal:
int f(), i = 42;
But it is indeed not allowed to omit the semicolon entirely in these cases, so it would be somewhat surprising if either was taken as an example of a declaration without a following semicolon. In fact, the following is illegal:
void *p, f() {}
Other than a (mere) function declaration, a function definition cannot be combined with any other declaration or definition to the same type-specifier. (If this were legal, it would define both a void *p and a void f() {}.)
In any case, this seems to be a "gotcha" type of question that should not be in an intermediate programming test.
(Oh, by the way, please don't actually write code like int f(), i = 42;.)
add a comment |
In addition to the "a definition is also a declaration" thing, the following is legal C++:
int f(), g();
This declares two functions,f and g, both without arguments and with a return type of int, but the definition of f is not followed (immediately) by a semicolon. Likewise, this is legal:
int f(), i = 42;
But it is indeed not allowed to omit the semicolon entirely in these cases, so it would be somewhat surprising if either was taken as an example of a declaration without a following semicolon. In fact, the following is illegal:
void *p, f() {}
Other than a (mere) function declaration, a function definition cannot be combined with any other declaration or definition to the same type-specifier. (If this were legal, it would define both a void *p and a void f() {}.)
In any case, this seems to be a "gotcha" type of question that should not be in an intermediate programming test.
(Oh, by the way, please don't actually write code like int f(), i = 42;.)
add a comment |
In addition to the "a definition is also a declaration" thing, the following is legal C++:
int f(), g();
This declares two functions,f and g, both without arguments and with a return type of int, but the definition of f is not followed (immediately) by a semicolon. Likewise, this is legal:
int f(), i = 42;
But it is indeed not allowed to omit the semicolon entirely in these cases, so it would be somewhat surprising if either was taken as an example of a declaration without a following semicolon. In fact, the following is illegal:
void *p, f() {}
Other than a (mere) function declaration, a function definition cannot be combined with any other declaration or definition to the same type-specifier. (If this were legal, it would define both a void *p and a void f() {}.)
In any case, this seems to be a "gotcha" type of question that should not be in an intermediate programming test.
(Oh, by the way, please don't actually write code like int f(), i = 42;.)
In addition to the "a definition is also a declaration" thing, the following is legal C++:
int f(), g();
This declares two functions,f and g, both without arguments and with a return type of int, but the definition of f is not followed (immediately) by a semicolon. Likewise, this is legal:
int f(), i = 42;
But it is indeed not allowed to omit the semicolon entirely in these cases, so it would be somewhat surprising if either was taken as an example of a declaration without a following semicolon. In fact, the following is illegal:
void *p, f() {}
Other than a (mere) function declaration, a function definition cannot be combined with any other declaration or definition to the same type-specifier. (If this were legal, it would define both a void *p and a void f() {}.)
In any case, this seems to be a "gotcha" type of question that should not be in an intermediate programming test.
(Oh, by the way, please don't actually write code like int f(), i = 42;.)
answered 15 hours ago
Arne VogelArne Vogel
4,20511126
4,20511126
add a comment |
add a comment |
The other answers and comments call out several of the many ways that this is a horrid, misleading and badly-written question. But there is another problem that no one else has identified yet. The question is:
A semicolon (';') is not needed after a function declaration. True or False.
OK, let's look at a function declaration:
int func(); /* */
/* ^ */
/* | */
/* That whitespace is "after the function declaration". */
That whole thing is the declaration. The declaration is not int func() and then followed by a ;. The declaration is int func(); and then is followed by whitespace.
So, the question is: is a semicolon needed after the declaration? Of course not. The declaration already has a semicolon in it which terminated it. A semicolon after the declaration would be pointless. By contrast, int func(); ; would be a semicolon after a function declaration.
The question was almost certainly intended to ask the question "true or false: the last token in a function declaration is always a semicolon" But that's not the question that they wrote, because the author of the quiz was not thinking clearly about the problem.
My advice is to avoid programming language quizzes altogether. They're pretty awful.
Fun fact, while we are on the subject. In C#, these are all legal:
class C {}
class D {};
struct E {}
struct F {};
In C#, a class or struct declaration may end in a semicolon, or not, at your discretion. This odd little feature was added for the benefit of C/C++ programmers coming to C# who have it in their fingertips that type declarations end in a pointless semicolon; the design team didn't want to punish them for having this habit. :-)
3
I would edit the last :-) to ;-)
– Hila DG
8 hours ago
My advice is to avoid programming language quizzes altogether. They're pretty awful.; worth of million upvotes advice!
– haccks
1 hour ago
add a comment |
The other answers and comments call out several of the many ways that this is a horrid, misleading and badly-written question. But there is another problem that no one else has identified yet. The question is:
A semicolon (';') is not needed after a function declaration. True or False.
OK, let's look at a function declaration:
int func(); /* */
/* ^ */
/* | */
/* That whitespace is "after the function declaration". */
That whole thing is the declaration. The declaration is not int func() and then followed by a ;. The declaration is int func(); and then is followed by whitespace.
So, the question is: is a semicolon needed after the declaration? Of course not. The declaration already has a semicolon in it which terminated it. A semicolon after the declaration would be pointless. By contrast, int func(); ; would be a semicolon after a function declaration.
The question was almost certainly intended to ask the question "true or false: the last token in a function declaration is always a semicolon" But that's not the question that they wrote, because the author of the quiz was not thinking clearly about the problem.
My advice is to avoid programming language quizzes altogether. They're pretty awful.
Fun fact, while we are on the subject. In C#, these are all legal:
class C {}
class D {};
struct E {}
struct F {};
In C#, a class or struct declaration may end in a semicolon, or not, at your discretion. This odd little feature was added for the benefit of C/C++ programmers coming to C# who have it in their fingertips that type declarations end in a pointless semicolon; the design team didn't want to punish them for having this habit. :-)
3
I would edit the last :-) to ;-)
– Hila DG
8 hours ago
My advice is to avoid programming language quizzes altogether. They're pretty awful.; worth of million upvotes advice!
– haccks
1 hour ago
add a comment |
The other answers and comments call out several of the many ways that this is a horrid, misleading and badly-written question. But there is another problem that no one else has identified yet. The question is:
A semicolon (';') is not needed after a function declaration. True or False.
OK, let's look at a function declaration:
int func(); /* */
/* ^ */
/* | */
/* That whitespace is "after the function declaration". */
That whole thing is the declaration. The declaration is not int func() and then followed by a ;. The declaration is int func(); and then is followed by whitespace.
So, the question is: is a semicolon needed after the declaration? Of course not. The declaration already has a semicolon in it which terminated it. A semicolon after the declaration would be pointless. By contrast, int func(); ; would be a semicolon after a function declaration.
The question was almost certainly intended to ask the question "true or false: the last token in a function declaration is always a semicolon" But that's not the question that they wrote, because the author of the quiz was not thinking clearly about the problem.
My advice is to avoid programming language quizzes altogether. They're pretty awful.
Fun fact, while we are on the subject. In C#, these are all legal:
class C {}
class D {};
struct E {}
struct F {};
In C#, a class or struct declaration may end in a semicolon, or not, at your discretion. This odd little feature was added for the benefit of C/C++ programmers coming to C# who have it in their fingertips that type declarations end in a pointless semicolon; the design team didn't want to punish them for having this habit. :-)
The other answers and comments call out several of the many ways that this is a horrid, misleading and badly-written question. But there is another problem that no one else has identified yet. The question is:
A semicolon (';') is not needed after a function declaration. True or False.
OK, let's look at a function declaration:
int func(); /* */
/* ^ */
/* | */
/* That whitespace is "after the function declaration". */
That whole thing is the declaration. The declaration is not int func() and then followed by a ;. The declaration is int func(); and then is followed by whitespace.
So, the question is: is a semicolon needed after the declaration? Of course not. The declaration already has a semicolon in it which terminated it. A semicolon after the declaration would be pointless. By contrast, int func(); ; would be a semicolon after a function declaration.
The question was almost certainly intended to ask the question "true or false: the last token in a function declaration is always a semicolon" But that's not the question that they wrote, because the author of the quiz was not thinking clearly about the problem.
My advice is to avoid programming language quizzes altogether. They're pretty awful.
Fun fact, while we are on the subject. In C#, these are all legal:
class C {}
class D {};
struct E {}
struct F {};
In C#, a class or struct declaration may end in a semicolon, or not, at your discretion. This odd little feature was added for the benefit of C/C++ programmers coming to C# who have it in their fingertips that type declarations end in a pointless semicolon; the design team didn't want to punish them for having this habit. :-)
edited 6 hours ago
Peter Mortensen
13.7k1986111
13.7k1986111
answered 11 hours ago
Eric LippertEric Lippert
541k14610581943
541k14610581943
3
I would edit the last :-) to ;-)
– Hila DG
8 hours ago
My advice is to avoid programming language quizzes altogether. They're pretty awful.; worth of million upvotes advice!
– haccks
1 hour ago
add a comment |
3
I would edit the last :-) to ;-)
– Hila DG
8 hours ago
My advice is to avoid programming language quizzes altogether. They're pretty awful.; worth of million upvotes advice!
– haccks
1 hour ago
3
3
I would edit the last :-) to ;-)
– Hila DG
8 hours ago
I would edit the last :-) to ;-)
– Hila DG
8 hours ago
My advice is to avoid programming language quizzes altogether. They're pretty awful.; worth of million upvotes advice!
– haccks
1 hour ago
My advice is to avoid programming language quizzes altogether. They're pretty awful.; worth of million upvotes advice!
– haccks
1 hour ago
add a comment |
You can declare a function like this too:
int func(){
return 1;
}
the statement is very ambiguous. The right answer should be: it depends on how you declare the function.
Anyway, I'd have chosen false too, maybe you can report the question to someone.
Anyway, don't put the thing on a personal level. The important thing is that you understood how a function declaration-definition works, so don't worry about it too much, just make sure that the question will be at least checked and go on
– Luca Corsini
16 hours ago
5
Absolutely. Honestly, I learned more about function declaration-definition from getting the question wrong than I would've had I gotten in it correct.
– Logan
16 hours ago
@Logan don't worry too much. If you know how to write and read a function that's all you need. I personally hate these kind of questions that 1. are not well defined 2. test your theoretical knowledge of the syntax. To me it's like muscle memory. When I write each digit goes effortlessly to the key it is supposed to go, but if you give me a test about what keys should a digit press I would be completely hopeless without a keyboard to physically do the action ...
– bolov
13 hours ago
... Writing common syntax (e.g. like a function) will become a second nature to you. And when you will mess it up because you just switched languages, well... intellisense and syntax highlighting make for quick and efficient solutions. Invest your time and energy in something more useful.
– bolov
13 hours ago
add a comment |
You can declare a function like this too:
int func(){
return 1;
}
the statement is very ambiguous. The right answer should be: it depends on how you declare the function.
Anyway, I'd have chosen false too, maybe you can report the question to someone.
Anyway, don't put the thing on a personal level. The important thing is that you understood how a function declaration-definition works, so don't worry about it too much, just make sure that the question will be at least checked and go on
– Luca Corsini
16 hours ago
5
Absolutely. Honestly, I learned more about function declaration-definition from getting the question wrong than I would've had I gotten in it correct.
– Logan
16 hours ago
@Logan don't worry too much. If you know how to write and read a function that's all you need. I personally hate these kind of questions that 1. are not well defined 2. test your theoretical knowledge of the syntax. To me it's like muscle memory. When I write each digit goes effortlessly to the key it is supposed to go, but if you give me a test about what keys should a digit press I would be completely hopeless without a keyboard to physically do the action ...
– bolov
13 hours ago
... Writing common syntax (e.g. like a function) will become a second nature to you. And when you will mess it up because you just switched languages, well... intellisense and syntax highlighting make for quick and efficient solutions. Invest your time and energy in something more useful.
– bolov
13 hours ago
add a comment |
You can declare a function like this too:
int func(){
return 1;
}
the statement is very ambiguous. The right answer should be: it depends on how you declare the function.
Anyway, I'd have chosen false too, maybe you can report the question to someone.
You can declare a function like this too:
int func(){
return 1;
}
the statement is very ambiguous. The right answer should be: it depends on how you declare the function.
Anyway, I'd have chosen false too, maybe you can report the question to someone.
answered 16 hours ago
Luca CorsiniLuca Corsini
324111
324111
Anyway, don't put the thing on a personal level. The important thing is that you understood how a function declaration-definition works, so don't worry about it too much, just make sure that the question will be at least checked and go on
– Luca Corsini
16 hours ago
5
Absolutely. Honestly, I learned more about function declaration-definition from getting the question wrong than I would've had I gotten in it correct.
– Logan
16 hours ago
@Logan don't worry too much. If you know how to write and read a function that's all you need. I personally hate these kind of questions that 1. are not well defined 2. test your theoretical knowledge of the syntax. To me it's like muscle memory. When I write each digit goes effortlessly to the key it is supposed to go, but if you give me a test about what keys should a digit press I would be completely hopeless without a keyboard to physically do the action ...
– bolov
13 hours ago
... Writing common syntax (e.g. like a function) will become a second nature to you. And when you will mess it up because you just switched languages, well... intellisense and syntax highlighting make for quick and efficient solutions. Invest your time and energy in something more useful.
– bolov
13 hours ago
add a comment |
Anyway, don't put the thing on a personal level. The important thing is that you understood how a function declaration-definition works, so don't worry about it too much, just make sure that the question will be at least checked and go on
– Luca Corsini
16 hours ago
5
Absolutely. Honestly, I learned more about function declaration-definition from getting the question wrong than I would've had I gotten in it correct.
– Logan
16 hours ago
@Logan don't worry too much. If you know how to write and read a function that's all you need. I personally hate these kind of questions that 1. are not well defined 2. test your theoretical knowledge of the syntax. To me it's like muscle memory. When I write each digit goes effortlessly to the key it is supposed to go, but if you give me a test about what keys should a digit press I would be completely hopeless without a keyboard to physically do the action ...
– bolov
13 hours ago
... Writing common syntax (e.g. like a function) will become a second nature to you. And when you will mess it up because you just switched languages, well... intellisense and syntax highlighting make for quick and efficient solutions. Invest your time and energy in something more useful.
– bolov
13 hours ago
Anyway, don't put the thing on a personal level. The important thing is that you understood how a function declaration-definition works, so don't worry about it too much, just make sure that the question will be at least checked and go on
– Luca Corsini
16 hours ago
Anyway, don't put the thing on a personal level. The important thing is that you understood how a function declaration-definition works, so don't worry about it too much, just make sure that the question will be at least checked and go on
– Luca Corsini
16 hours ago
5
5
Absolutely. Honestly, I learned more about function declaration-definition from getting the question wrong than I would've had I gotten in it correct.
– Logan
16 hours ago
Absolutely. Honestly, I learned more about function declaration-definition from getting the question wrong than I would've had I gotten in it correct.
– Logan
16 hours ago
@Logan don't worry too much. If you know how to write and read a function that's all you need. I personally hate these kind of questions that 1. are not well defined 2. test your theoretical knowledge of the syntax. To me it's like muscle memory. When I write each digit goes effortlessly to the key it is supposed to go, but if you give me a test about what keys should a digit press I would be completely hopeless without a keyboard to physically do the action ...
– bolov
13 hours ago
@Logan don't worry too much. If you know how to write and read a function that's all you need. I personally hate these kind of questions that 1. are not well defined 2. test your theoretical knowledge of the syntax. To me it's like muscle memory. When I write each digit goes effortlessly to the key it is supposed to go, but if you give me a test about what keys should a digit press I would be completely hopeless without a keyboard to physically do the action ...
– bolov
13 hours ago
... Writing common syntax (e.g. like a function) will become a second nature to you. And when you will mess it up because you just switched languages, well... intellisense and syntax highlighting make for quick and efficient solutions. Invest your time and energy in something more useful.
– bolov
13 hours ago
... Writing common syntax (e.g. like a function) will become a second nature to you. And when you will mess it up because you just switched languages, well... intellisense and syntax highlighting make for quick and efficient solutions. Invest your time and energy in something more useful.
– bolov
13 hours ago
add a comment |
This depond on on the condition weather we are declaring or defining the function.
If we declare the the function we need to include semicolon (;) and if we are defining the function semicolon is not needed .
Decleration :
int add(int, int);
Defining the function :
int add(int a, int b)
New contributor
Rocx En Ruff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The problem with this answer is that it suggests that definitions and declaration are mutually exclusive. In fact, every definition is a declaration; definitions are a subset of declarations.
– MSalters
45 mins ago
add a comment |
This depond on on the condition weather we are declaring or defining the function.
If we declare the the function we need to include semicolon (;) and if we are defining the function semicolon is not needed .
Decleration :
int add(int, int);
Defining the function :
int add(int a, int b)
New contributor
Rocx En Ruff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The problem with this answer is that it suggests that definitions and declaration are mutually exclusive. In fact, every definition is a declaration; definitions are a subset of declarations.
– MSalters
45 mins ago
add a comment |
This depond on on the condition weather we are declaring or defining the function.
If we declare the the function we need to include semicolon (;) and if we are defining the function semicolon is not needed .
Decleration :
int add(int, int);
Defining the function :
int add(int a, int b)
New contributor
Rocx En Ruff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This depond on on the condition weather we are declaring or defining the function.
If we declare the the function we need to include semicolon (;) and if we are defining the function semicolon is not needed .
Decleration :
int add(int, int);
Defining the function :
int add(int a, int b)
New contributor
Rocx En Ruff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Rocx En Ruff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 1 hour ago
Rocx En RuffRocx En Ruff
11
11
New contributor
Rocx En Ruff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Rocx En Ruff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Rocx En Ruff is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The problem with this answer is that it suggests that definitions and declaration are mutually exclusive. In fact, every definition is a declaration; definitions are a subset of declarations.
– MSalters
45 mins ago
add a comment |
The problem with this answer is that it suggests that definitions and declaration are mutually exclusive. In fact, every definition is a declaration; definitions are a subset of declarations.
– MSalters
45 mins ago
The problem with this answer is that it suggests that definitions and declaration are mutually exclusive. In fact, every definition is a declaration; definitions are a subset of declarations.
– MSalters
45 mins ago
The problem with this answer is that it suggests that definitions and declaration are mutually exclusive. In fact, every definition is a declaration; definitions are a subset of declarations.
– MSalters
45 mins ago
add a comment |
Logan is a new contributor. Be nice, and check out our Code of Conduct.
Logan is a new contributor. Be nice, and check out our Code of Conduct.
Logan is a new contributor. Be nice, and check out our Code of Conduct.
Logan is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54790795%2fa-semicolon-is-not-needed-after-a-function-declaration-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
18
A definition is also a declaration. But I would say your answer was correct.
– Neil Butterworth
16 hours ago
54
It's a tricky nitpicking question and has no bearing on anyone's ability to program well.
– phonetagger
16 hours ago
16
I always find the questions, that result in double-negatives, confusing. In my mind, such questions are designed to trip students up. Why couldn't the question be formed in a following way: "A semicolon (';') is always needed after a function declaration. True or False."? :/
– Algirdas Preidžius
16 hours ago
6
@phonetagger All this confusion goes to show how badly worded the question is.
– François Andrieux
16 hours ago
14
Hanlon's Razor suggests that the author of the test mixed up "declaration" and "definition".
– Sneftel
16 hours ago