The Wayback Machine - https://web.archive.org/web/20230512155242/https://www.geeksforgeeks.org/dc-command-in-linux-with-examples/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

dc command in Linux with examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

dc command in Linux is used to evaluate arithmetic expressions. It evaluates expressions in the form of a postfix expression. Entering a number pushes it into the stack and entering an operator evaluates an expression and pushes the result back into the stack. It can evaluate +, -, /, *, %, ^. Different commands can be used to manipulate stack. 

Syntax: 
 

dc [OPTION] [file ...]

Below table illustrate the different commands and their explanation: 

 

CommandOperation
pPrints the value on the top of the stack and ends the statement with a newline.
nPrints the value on the top of the stack and ends the line with a null statement.
fPrints the entire stack, without any alteration.
PPops the value from the top of the stack.
cClear the stack.
dDuplicates the top value and push it into the main stack.
rReverses the order of top two elements in the stack.
ZPops the value from the stack, calculate the number of digits in it and pushes that number.
XPops the value from the stack, calculate the number of fraction digits in it and pushes that number.
zPushes the stack length into the stack.
iPops the value from the stack and uses it as input radix.
oPops the value from the stack and uses it as output radix.
kPops the values from the stack and uses it to set precision.
IPushes the value of input radix into the stack.
OPushes the value of output radix into the stack
KPushes the precision value into the stack.

Example 1:
 

Example 2: 

 

Note: In second example, the output changes because we changed the output-radix. 

Options: 

 

  • expression : This command is used to evaluate a particular expression.
     

  • file : This command is used to evaluate the contents of the file.
     

  • help : This command displays help information.
     

  • version: This command is used to display version information.
     

My Personal Notes arrow_drop_up
Last Updated : 10 Feb, 2022
Like Article
Save Article
Similar Reads
Related Tutorials