Why no semicolon gives errors but too many of them don't?K&R - Exercise 1-9 - Removing SpacesWhat does ; random string ; represent in CC++ Returning and Inserting a 2D array objectWhy should I use a semicolon after every function in javascript?Why so many semicolons in JavaScript?Why is `a (b.c do;end)` not a syntactically correct Ruby program?Porting klib's knetfile.c|h to windows, when I sub in the “windows unistd.h”, I get error C2036: 'void *' : unknown sizeWhy don't these Semicolons Produce an Error?Why does the statement “2i;” NOT cause a compiler error?How do I return null if my string has no null terminatorWhy doesn't the compiler report a missing semicolon?Why does c = ++(a+b) give compilation error?
Not been paid even after reminding the Treasurer; what should I do?
Why do dragons like shiny stuff?
Premier League simulation
split large formula in align
Non-small objects in categories
Can I enter a rental property without giving notice if I'm afraid a tenant may be hurt?
Will a research paper be retracted if the code (which was made publically available ) is shown have a flaw in the logic?
How to check a file was encrypted (really & correctly)
Can you take actions after being healed at 0hp?
How to realistically deal with a shield user?
How can I perform a deterministic physics simulation?
Can I enter Switzerland with only my London Driver's License?
Generate a random point outside a given rectangle within a map
Could an areostationary satellite help locate asteroids?
What's going on with an item that starts with an hbox?
Did Captain America make out with his niece?
Did Apollo leave poop on the moon?
What prevents ads from reading my password as I type it?
Why should I "believe in" weak solutions to PDEs?
How easy is it to get a gun illegally in the United States?
Do some languages mention the top limit of a range first?
Why does putting a dot after the URL remove login information?
Why do proponents of guns oppose gun competency tests?
Why do cheap flights with a layover get more expensive when you split them up into separate flights?
Why no semicolon gives errors but too many of them don't?
K&R - Exercise 1-9 - Removing SpacesWhat does ; random string ; represent in CC++ Returning and Inserting a 2D array objectWhy should I use a semicolon after every function in javascript?Why so many semicolons in JavaScript?Why is `a (b.c do;end)` not a syntactically correct Ruby program?Porting klib's knetfile.c|h to windows, when I sub in the “windows unistd.h”, I get error C2036: 'void *' : unknown sizeWhy don't these Semicolons Produce an Error?Why does the statement “2i;” NOT cause a compiler error?How do I return null if my string has no null terminatorWhy doesn't the compiler report a missing semicolon?Why does c = ++(a+b) give compilation error?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Consider this C code:
#include <stdio.h>;
int main(void)
puts("Hello, world!");; ;
;
return 0; ;
; ;
;
Here I've put semicolons almost everywhere possible. Just for fun. But surprisingly it worked! I got a warning about the semicolon after include but other absolutely wrong semicolons worked. If I forget to put a semicolon after puts
, I'll get the following error
error: expected ';' before 'return'
Why don't lots of wrong and useless semicolons cause errors? To my mind they should be treated as syntax errors.
c syntax
add a comment |
Consider this C code:
#include <stdio.h>;
int main(void)
puts("Hello, world!");; ;
;
return 0; ;
; ;
;
Here I've put semicolons almost everywhere possible. Just for fun. But surprisingly it worked! I got a warning about the semicolon after include but other absolutely wrong semicolons worked. If I forget to put a semicolon after puts
, I'll get the following error
error: expected ';' before 'return'
Why don't lots of wrong and useless semicolons cause errors? To my mind they should be treated as syntax errors.
c syntax
add a comment |
Consider this C code:
#include <stdio.h>;
int main(void)
puts("Hello, world!");; ;
;
return 0; ;
; ;
;
Here I've put semicolons almost everywhere possible. Just for fun. But surprisingly it worked! I got a warning about the semicolon after include but other absolutely wrong semicolons worked. If I forget to put a semicolon after puts
, I'll get the following error
error: expected ';' before 'return'
Why don't lots of wrong and useless semicolons cause errors? To my mind they should be treated as syntax errors.
c syntax
Consider this C code:
#include <stdio.h>;
int main(void)
puts("Hello, world!");; ;
;
return 0; ;
; ;
;
Here I've put semicolons almost everywhere possible. Just for fun. But surprisingly it worked! I got a warning about the semicolon after include but other absolutely wrong semicolons worked. If I forget to put a semicolon after puts
, I'll get the following error
error: expected ';' before 'return'
Why don't lots of wrong and useless semicolons cause errors? To my mind they should be treated as syntax errors.
c syntax
c syntax
edited Mar 27 at 3:42
Bhargav Rao♦
32.3k21 gold badges94 silver badges115 bronze badges
32.3k21 gold badges94 silver badges115 bronze badges
asked May 16 '15 at 18:18
ForceBruForceBru
23.5k8 gold badges35 silver badges59 bronze badges
23.5k8 gold badges35 silver badges59 bronze badges
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
A single semicolon constructs a null statement. It's not only legal, it's also useful in some cases, for instance, a while
/ for
loop that doesn't need a real body. An example:
while (*s++ = *t++)
;
C11 6.8.3 Expression and null statements
A null statement (consisting of just a semicolon) performs no operations.
The only syntax error is this line:
#include <stdio.h>;
Then how did it compile if a semicolon after an include is an error?
– ForceBru
May 16 '15 at 18:24
@ForceBru Isn't there a warning?
– Yu Hao
May 16 '15 at 18:30
yes, sure, but it's a warning, not an error, isn't it? So, it's just deprecated but OK.
– ForceBru
May 16 '15 at 18:31
2
@ForceBru A warning doesn't mean it's deprecated. I'll say it's more like a small error, not fatal, but a diagnostic messages is necessary.
– Yu Hao
May 16 '15 at 18:34
@ForceBru The;
will remain after the include has been resolved by the preprocessor, so it depends on what the included source contains, about it may change the source to become invalid or just be another null statement.
– dhein
Jun 18 '15 at 12:17
|
show 1 more comment
semicolon means end of a statement whether it is empty or not. No semicolon means you have not closed/ end last statement but started a new one which gives error. too many semicolon indicates end of blank statement each. So, it does not give error
add a comment |
Why should an empty statement be an error? It is not.
add a comment |
The ;
(statement delimiter) is always used to specify that particular statement is ended. There after next statement is executed.
If you dont put delimeter, then it will consider the next statement with the current statement and execute. And that gives a syntatic error.
But in other case when we put multiple delimeters eg:
int a;;;;;
In that case we have 5 statements, in which int a
is first statement and next four statements are null statements that will be removed by compiler at during compilation.
See some interesting cases for this question:
int main()
int a=0 ;,;
return 0;
when we change above programj it it still works:
int main()
int a=0 ,; /*change done*/
return 0;
add a comment |
The ;
is a statement delimiter in C as mentioned in the above answer. Rahul's answer is perfectly correct, just that you can see this answer to a question which asks why a statement in C ends with a semicolon. Thus, when you understand why a semicolon is used, you will understand what happens when you put too many semicolons.
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
);
);
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%2f30279168%2fwhy-no-semicolon-gives-errors-but-too-many-of-them-dont%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
A single semicolon constructs a null statement. It's not only legal, it's also useful in some cases, for instance, a while
/ for
loop that doesn't need a real body. An example:
while (*s++ = *t++)
;
C11 6.8.3 Expression and null statements
A null statement (consisting of just a semicolon) performs no operations.
The only syntax error is this line:
#include <stdio.h>;
Then how did it compile if a semicolon after an include is an error?
– ForceBru
May 16 '15 at 18:24
@ForceBru Isn't there a warning?
– Yu Hao
May 16 '15 at 18:30
yes, sure, but it's a warning, not an error, isn't it? So, it's just deprecated but OK.
– ForceBru
May 16 '15 at 18:31
2
@ForceBru A warning doesn't mean it's deprecated. I'll say it's more like a small error, not fatal, but a diagnostic messages is necessary.
– Yu Hao
May 16 '15 at 18:34
@ForceBru The;
will remain after the include has been resolved by the preprocessor, so it depends on what the included source contains, about it may change the source to become invalid or just be another null statement.
– dhein
Jun 18 '15 at 12:17
|
show 1 more comment
A single semicolon constructs a null statement. It's not only legal, it's also useful in some cases, for instance, a while
/ for
loop that doesn't need a real body. An example:
while (*s++ = *t++)
;
C11 6.8.3 Expression and null statements
A null statement (consisting of just a semicolon) performs no operations.
The only syntax error is this line:
#include <stdio.h>;
Then how did it compile if a semicolon after an include is an error?
– ForceBru
May 16 '15 at 18:24
@ForceBru Isn't there a warning?
– Yu Hao
May 16 '15 at 18:30
yes, sure, but it's a warning, not an error, isn't it? So, it's just deprecated but OK.
– ForceBru
May 16 '15 at 18:31
2
@ForceBru A warning doesn't mean it's deprecated. I'll say it's more like a small error, not fatal, but a diagnostic messages is necessary.
– Yu Hao
May 16 '15 at 18:34
@ForceBru The;
will remain after the include has been resolved by the preprocessor, so it depends on what the included source contains, about it may change the source to become invalid or just be another null statement.
– dhein
Jun 18 '15 at 12:17
|
show 1 more comment
A single semicolon constructs a null statement. It's not only legal, it's also useful in some cases, for instance, a while
/ for
loop that doesn't need a real body. An example:
while (*s++ = *t++)
;
C11 6.8.3 Expression and null statements
A null statement (consisting of just a semicolon) performs no operations.
The only syntax error is this line:
#include <stdio.h>;
A single semicolon constructs a null statement. It's not only legal, it's also useful in some cases, for instance, a while
/ for
loop that doesn't need a real body. An example:
while (*s++ = *t++)
;
C11 6.8.3 Expression and null statements
A null statement (consisting of just a semicolon) performs no operations.
The only syntax error is this line:
#include <stdio.h>;
edited May 16 '15 at 18:24
answered May 16 '15 at 18:23
Yu HaoYu Hao
100k22 gold badges177 silver badges230 bronze badges
100k22 gold badges177 silver badges230 bronze badges
Then how did it compile if a semicolon after an include is an error?
– ForceBru
May 16 '15 at 18:24
@ForceBru Isn't there a warning?
– Yu Hao
May 16 '15 at 18:30
yes, sure, but it's a warning, not an error, isn't it? So, it's just deprecated but OK.
– ForceBru
May 16 '15 at 18:31
2
@ForceBru A warning doesn't mean it's deprecated. I'll say it's more like a small error, not fatal, but a diagnostic messages is necessary.
– Yu Hao
May 16 '15 at 18:34
@ForceBru The;
will remain after the include has been resolved by the preprocessor, so it depends on what the included source contains, about it may change the source to become invalid or just be another null statement.
– dhein
Jun 18 '15 at 12:17
|
show 1 more comment
Then how did it compile if a semicolon after an include is an error?
– ForceBru
May 16 '15 at 18:24
@ForceBru Isn't there a warning?
– Yu Hao
May 16 '15 at 18:30
yes, sure, but it's a warning, not an error, isn't it? So, it's just deprecated but OK.
– ForceBru
May 16 '15 at 18:31
2
@ForceBru A warning doesn't mean it's deprecated. I'll say it's more like a small error, not fatal, but a diagnostic messages is necessary.
– Yu Hao
May 16 '15 at 18:34
@ForceBru The;
will remain after the include has been resolved by the preprocessor, so it depends on what the included source contains, about it may change the source to become invalid or just be another null statement.
– dhein
Jun 18 '15 at 12:17
Then how did it compile if a semicolon after an include is an error?
– ForceBru
May 16 '15 at 18:24
Then how did it compile if a semicolon after an include is an error?
– ForceBru
May 16 '15 at 18:24
@ForceBru Isn't there a warning?
– Yu Hao
May 16 '15 at 18:30
@ForceBru Isn't there a warning?
– Yu Hao
May 16 '15 at 18:30
yes, sure, but it's a warning, not an error, isn't it? So, it's just deprecated but OK.
– ForceBru
May 16 '15 at 18:31
yes, sure, but it's a warning, not an error, isn't it? So, it's just deprecated but OK.
– ForceBru
May 16 '15 at 18:31
2
2
@ForceBru A warning doesn't mean it's deprecated. I'll say it's more like a small error, not fatal, but a diagnostic messages is necessary.
– Yu Hao
May 16 '15 at 18:34
@ForceBru A warning doesn't mean it's deprecated. I'll say it's more like a small error, not fatal, but a diagnostic messages is necessary.
– Yu Hao
May 16 '15 at 18:34
@ForceBru The
;
will remain after the include has been resolved by the preprocessor, so it depends on what the included source contains, about it may change the source to become invalid or just be another null statement.– dhein
Jun 18 '15 at 12:17
@ForceBru The
;
will remain after the include has been resolved by the preprocessor, so it depends on what the included source contains, about it may change the source to become invalid or just be another null statement.– dhein
Jun 18 '15 at 12:17
|
show 1 more comment
semicolon means end of a statement whether it is empty or not. No semicolon means you have not closed/ end last statement but started a new one which gives error. too many semicolon indicates end of blank statement each. So, it does not give error
add a comment |
semicolon means end of a statement whether it is empty or not. No semicolon means you have not closed/ end last statement but started a new one which gives error. too many semicolon indicates end of blank statement each. So, it does not give error
add a comment |
semicolon means end of a statement whether it is empty or not. No semicolon means you have not closed/ end last statement but started a new one which gives error. too many semicolon indicates end of blank statement each. So, it does not give error
semicolon means end of a statement whether it is empty or not. No semicolon means you have not closed/ end last statement but started a new one which gives error. too many semicolon indicates end of blank statement each. So, it does not give error
answered May 16 '15 at 18:25
akmnahidakmnahid
4292 gold badges5 silver badges14 bronze badges
4292 gold badges5 silver badges14 bronze badges
add a comment |
add a comment |
Why should an empty statement be an error? It is not.
add a comment |
Why should an empty statement be an error? It is not.
add a comment |
Why should an empty statement be an error? It is not.
Why should an empty statement be an error? It is not.
edited May 16 '15 at 18:30
Hurkyl
14.1k2 gold badges27 silver badges46 bronze badges
14.1k2 gold badges27 silver badges46 bronze badges
answered May 16 '15 at 18:21
Ed HealEd Heal
49.1k14 gold badges69 silver badges105 bronze badges
49.1k14 gold badges69 silver badges105 bronze badges
add a comment |
add a comment |
The ;
(statement delimiter) is always used to specify that particular statement is ended. There after next statement is executed.
If you dont put delimeter, then it will consider the next statement with the current statement and execute. And that gives a syntatic error.
But in other case when we put multiple delimeters eg:
int a;;;;;
In that case we have 5 statements, in which int a
is first statement and next four statements are null statements that will be removed by compiler at during compilation.
See some interesting cases for this question:
int main()
int a=0 ;,;
return 0;
when we change above programj it it still works:
int main()
int a=0 ,; /*change done*/
return 0;
add a comment |
The ;
(statement delimiter) is always used to specify that particular statement is ended. There after next statement is executed.
If you dont put delimeter, then it will consider the next statement with the current statement and execute. And that gives a syntatic error.
But in other case when we put multiple delimeters eg:
int a;;;;;
In that case we have 5 statements, in which int a
is first statement and next four statements are null statements that will be removed by compiler at during compilation.
See some interesting cases for this question:
int main()
int a=0 ;,;
return 0;
when we change above programj it it still works:
int main()
int a=0 ,; /*change done*/
return 0;
add a comment |
The ;
(statement delimiter) is always used to specify that particular statement is ended. There after next statement is executed.
If you dont put delimeter, then it will consider the next statement with the current statement and execute. And that gives a syntatic error.
But in other case when we put multiple delimeters eg:
int a;;;;;
In that case we have 5 statements, in which int a
is first statement and next four statements are null statements that will be removed by compiler at during compilation.
See some interesting cases for this question:
int main()
int a=0 ;,;
return 0;
when we change above programj it it still works:
int main()
int a=0 ,; /*change done*/
return 0;
The ;
(statement delimiter) is always used to specify that particular statement is ended. There after next statement is executed.
If you dont put delimeter, then it will consider the next statement with the current statement and execute. And that gives a syntatic error.
But in other case when we put multiple delimeters eg:
int a;;;;;
In that case we have 5 statements, in which int a
is first statement and next four statements are null statements that will be removed by compiler at during compilation.
See some interesting cases for this question:
int main()
int a=0 ;,;
return 0;
when we change above programj it it still works:
int main()
int a=0 ,; /*change done*/
return 0;
answered May 16 '15 at 18:34
Rahul RainaRahul Raina
1,91815 silver badges25 bronze badges
1,91815 silver badges25 bronze badges
add a comment |
add a comment |
The ;
is a statement delimiter in C as mentioned in the above answer. Rahul's answer is perfectly correct, just that you can see this answer to a question which asks why a statement in C ends with a semicolon. Thus, when you understand why a semicolon is used, you will understand what happens when you put too many semicolons.
add a comment |
The ;
is a statement delimiter in C as mentioned in the above answer. Rahul's answer is perfectly correct, just that you can see this answer to a question which asks why a statement in C ends with a semicolon. Thus, when you understand why a semicolon is used, you will understand what happens when you put too many semicolons.
add a comment |
The ;
is a statement delimiter in C as mentioned in the above answer. Rahul's answer is perfectly correct, just that you can see this answer to a question which asks why a statement in C ends with a semicolon. Thus, when you understand why a semicolon is used, you will understand what happens when you put too many semicolons.
The ;
is a statement delimiter in C as mentioned in the above answer. Rahul's answer is perfectly correct, just that you can see this answer to a question which asks why a statement in C ends with a semicolon. Thus, when you understand why a semicolon is used, you will understand what happens when you put too many semicolons.
edited May 23 '17 at 12:01
Community♦
11 silver badge
11 silver badge
answered Jan 14 '16 at 6:22
Ashish AhujaAshish Ahuja
3,8309 gold badges38 silver badges57 bronze badges
3,8309 gold badges38 silver badges57 bronze badges
add a comment |
add a comment |
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%2f30279168%2fwhy-no-semicolon-gives-errors-but-too-many-of-them-dont%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