What is %1 in Programming?

%1 is a placeholder for the first argument in many programming languages. It can also be used to represent the current directory, or as an input prompt when setting interactive commands.

In programming, % means to substitute the text in brackets for what is inside it. So when you see “%s” in a program and put your cursor after it, this would mean that whatever follows (the string) should be replaced by “%s.” So in most cases, “%1” can be understood as the first argument.

Table of Contents

Example in a batch file

When used in a script, or command line, %1 is a variable that represents data from the input queue. For example, in a batch file, %1 can print what has been typed.

example.bat file content:

@echo off
echo Hello %1
pause

If we run the command example.bat TLDevTech, it will print out “Hello TLDevTech”.

Example in PHP

In a PHP format function, %1 stands for the first argument.

$format = '%2$s is %1$d years old';
echo sprintf($format, 20, 'John');
//output: John is 20 years old.

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close