Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
NOP (code)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== C and derivatives === The simplest NOP statement in C is the ''null statement'', which is just a semi-colon in a context requiring a statement. Most C compilers generate no code for null statements, which has historical and performance reasons. ; An empty block (compound statement) is also a NOP, and may be more legible, but will still have no code generated for it by the compiler. {} In some cases, such as the body of a function, a block must be used, but this can be empty. In C, statements cannot be empty—simple statements must end with a <code>;</code> (semicolon) while compound statements are enclosed in <code>{}</code> (braces), which does not itself need a following semicolon. Thus in contexts where a statement is grammatically required, some such null statement can be used. The null statement is useless by itself, but it can have a syntactic use in a wider context, e.g., within the context of a loop: <syntaxhighlight lang="c"> while (getchar() != '\n') {} </syntaxhighlight> alternatively, <syntaxhighlight lang="c"> while (getchar() != '\n') ; </syntaxhighlight> or more tersely: <syntaxhighlight lang="c"> while (getchar() != '\n'); </syntaxhighlight> (note that the last form may be confusing, and as such generates a warning with some compilers or compiler options, as semicolon usually indicates an end of function call instruction when placed after a parenthesis on the end of line). The above code continues calling the function <code>getchar()</code> until it returns a <code>\n</code> (newline) character, essentially fast-forwarding the current reading location of standard input to the beginning of next line.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)