#include< stdio.h>
#include< conio.h>
void main()
{
int x,y;
x=15;y=20;
clrscr();
printf("x=%d,y=%d\n",x,y);
swap(x,y);
printf("\n after interchanging x=%d,y=%d\n",x,y);
getch();
}
swap(int u,int v)
{
int temp;
temp=u;
u=v;
v=temp;
return;
}
/* Program for inerchanging two numbers demonstrating Call By Reference in C */
#include<>
#include<>
void swap(int *,int *);
void main()
{
int x,y;
x=15;y=20;
clrscr();
printf("x=%d,y=%d\n",x,y);
swap(&x,&y);
//printf("\n%x %x",&x,&y);
printf("\n after interchanging x=%d,y=%d\n",x,y);
getch();
}
void swap(int *u,int *v)
{
int temp;
temp=*u;
*u=*v;
*v=temp;
return;
}
So far e know how to write a simple program to display information typed in by you, the programmer, and how to describe your program with comments. That's great, but what about interacting with your user? Fortunately, it is also possible for your program to accept input. The function you use is known as cin, and is followed by the insertion operator >>.
Of course, before you try to receive input, you must have a place to store that input. In programming, input and data are stored in variables. There are several different types of variables which store different kinds of information (e.g. numbers versus letters); when you tell the compiler you are declaring a variable, you must include the data type along with the name of the variable. Several basic types include char, int, and float.
A variable of type char stores a single character, variables of type int store integers (numbers without decimal places), and variables of type float store numbers with decimal places. Each of these variable types - char, int, and float - is each a keyword that you use when you declare a variable.
Sometimes it can be confusing to have multiple variable types when it seems like some variable types are redundant (why have integer numbers when you have floats?). Using the right variable type can be important for making your code readable and for efficiency--some variables require more memory than others. Moreover, because of the way the numbers are actually stored in memory, a float is "inexact", and should not be used when you need to store an "exact" integer value.
To declare a variable you use the syntax "type
int x; char letter; float the_float;
It is permissible to declare multiple variables of the same type on the same line; each one should be separated by a comma.
int a, b, c, d;
If you were watching closely, you might have seen that declaration of a variable is always followed by a semicolon (note that this is the same procedure used when you call a function).
If you attempt to use a variable that you have not declared, your program will not be compiled or run, and you will receive an error message informing you that you have made a mistake. Usually, this is called an undeclared variable
.
Now is a good time to talk about an important concept that can easily throw you off: case sensitivity. Basically, in C++, whether you use uppercase or lowercase letters matters. The words Cat and cat mean different things to the compiler. In C++, all language keywords, all functions and all variables are case sensitive. A difference in case between your variable declaration and the use of the variable is one reason you might get an undeclared variable error.
A C++ program is a collection of commands, which tell the computer to do "something". This collection of commands is usually called C++ source code, source code or just code. Commands are either "functions" or "keywords". Keywords are a basic building block of the language, while functions are, in fact, usually written in terms of simpler functions--you'll see this in our very first program, below. (Confused? Think of it a bit like an outline for a book; the outline might show every chapter in the book; each chapter might have its own outline, composed of sections. Each section might have its own outline, or it might have all of the details written up.) Thankfully, C++ provides a great many common functions and keywords that you can use.
But how does a program actually start? Every program in C++ has one function, always named main, that is always called when your program first executes. From main, you can also call other functions whether they are written by us or, as mentioned earlier, provided by the compiler.
So how do you get access to those prewritten functions? To access those standard functions that comes with the compiler, you include a header with the #include directive. What this does is effectively take everything in the header and paste it into your program. Let's look at a working program:
#includeusing namespace std; int main() { cout<<"HEY, you, I'm on www.technary.com Oh, and Hello World!\n"; cin.get(); }
Let's look at the elements of the program. The #include is a "preprocessor" directive that tells the compiler to put code from the header called iostream into our program before actually creating the executable. By including header files, you gain access to many different functions. For example, the cout function requires iostream. Following the include is the statement, "using namespace std;". This line tells the compiler to use a group of functions that are part of the standard library (std). By including this line at the top of a file, you allow the program to use functions such as cout. The semicolon is part of the syntax of C++. It tells the compiler that you're at the end of a command. You will see later that the semicolon is used to end most commands in C++.
The next important line is int main(). This line tells the compiler that there is a function named main, and that the function returns an integer, hence int. The "curly braces" ({ and }) signal the beginning and end of functions and other code blocks. You can think of them as meaning BEGIN and END.
The next line of the program may seem strange. If you have programmed in another language, you might expect that print would be the function used to display text. In C++, however, the cout object is used to display text (pronounced "C out"). It uses the << symbols, known as "insertion operators", to indicate what to output. cout<< results in a function call with the ensuing text as an argument to the function. The quotes tell the compiler that you want to output the literal string as-is. The '\n' sequence is actually treated as a single character that stands for a newline (we'll talk about this later in more detail). It moves the cursor on your screen to the next line. Again, notice the semicolon: it is added onto the end of most lines, such as function calls, in C++.
The next command is cin.get(). This is another function call: it reads in input and expects the user to hit the return key. Many compiler environments will open a new console window, run the program, and then close the window. This command keeps that window from closing because the program is not done yet because it waits for you to hit enter. Including that line gives you time to see the program run.
Upon reaching the end of main, the closing brace, our program will return the value of 0 (and integer, hence why we told main to return an int) to the operating system. This return value is important as it can be used to tell the OS whether our program succeeded or not. A return value of 0 means success and is returned automatically (but only for main, other functions require you to manually return a value), but if we wanted to return something else, such as 1, we would have to do it with a return statement:
#includeusing namespace std; int main() { cout<<"HEY, you, I'm on www.technary.com Oh, and Hello World!\n"; cin.get(); return 1; }
So what is so special about C++? Why should you use C++ to develop your applications? First, C++ is not the best language to use in every instance. C++ is a great choice in most instances, but some special circumstances would be better suited to another language.
There are a few major advantages to using C++:
1. C++ allows expression of abstract ideas
C++ is a third generation language that allows a programmer to express their ideas at a high level as compared to assembly languages.
2. C++ still allows a programmer to keep low-level control
Even though C++ is a third generation language, it has some of the "feel" of an assembly language. It allows a programmmer to get down into the low-level workings and tune as necessary. C++ allows programmers strict control over memory management.
3. C++ has national standards (ANSI)
C++ is a language with national standards. This is good for many reasons. Code written in C++ that conforms to the national standards can be easily integrated with preexisting code. Also, this allows programmers to reuse certain common libraries, so certain common functions do not need to be written more than once, and these functions behave the same anywhere they are used.
4. C++ is reusable and object-oriented
C++ is an object-oriented language. This makes programming conceptually easier (once the object paradigm has been learned) and allows easy reuse of code, or parts of code through inheritance.
5. C++ is widely used and taught
C++ is a very widely used programming language. Because of this, there are many tools available for C++ programming, and there is a broad base of programmers contributing to the C++ "community".
What is C++?
C++ is a programming language. It literally means "increased C", reflecting its nature as an evolution of the C language.
Is it necessary to already know another programming language before learning C++?
Not necessarily. C++ is a simple and clear language in its expressions. It is true that a piece of code written with C++ may be seen by a stranger of programming a bit more cryptic than some other languages due to the intensive use of special characters ({}[]*&!|...), but once one knows the meaning of such characters it can be even more schematic and clear than other languages that rely more on English words.
Also, the simplification of the input/output interface of C++ in comparison to C and the incorporation of the standard template library in the language, makes the communication and manipulation of data in a program written in C++ as simple as in other languages, without losing the power it offers.
How can I learn C++?
There are many ways. Depending on the time you have and your preferences. The language is taught in many types of academic forms throughout the world, and can also be learnt by oneself with the help of tutorials and books. But you can learn it here on this website!
What is OOP: Object-oriented programming?
It is a programming model that treats programming from a perspective where each component is considered an object, with its own properties and methods, replacing or complementing structured programming paradigm, where the focus was on procedures and parameters.
Is C++ a proprietary language?
No. No one owns the C++ language. Anyone can use the language royalty-free.
What is ANSI-C++?
ANSI-C++ is the name by which the international ANSI/ISO standard for the C++ language is known. But before this standard was published, C++ was already widely used and therefore there is a lot of code out there written in pre-standard C++. Referring to ANSI-C++ explicitly differenciates it from pre-standard C++ code, which is incompatible in some ways.
How may I know if my compiler supports ANSI-C++?
The standard was published in 1998, followed by a revision in 2003. Some compilers older than the standard implement already some of its features, and many newer compilers don't implement all ANSI-C++ features. If you have doubts on whether your compiler will be able to compile ANSI-C++ code, you can try to compile a piece of code with some of the new features introduced mainly after the publication of the standard. For example, the following code fragment uses the bool type, and uses namespaces and templates.
#include
using namespace std;
template
bool ansisupported (T x) { return true; }
int main() {
if (ansisupported(0)) cout << "ANSI OK";
return 0;
}
OUTPUT:
ANSI OK
If your compiler is able to compile this program, you will be able to compile most of the existing ANSI-C++ code.
How can I make windowed programs?
You need a C++ compiler that can link code for your windowing environment (Windows, XWindow, MacOS, ...). Windowed programs do not generally use the console to communicate with the user. They use a set of functions or classes to manipulate windows instead, which are specific to each environment. Anyway the same principles apply both for console and windowed programs, except for communicating with the user.
What is Visual C++? And what does "visual programming" mean?
Visual C++ is the name of a C++ compiler with an integrated environment from Microsoft. It includes special tools that simplify the development of large applications as well as specific libraries that improve productivity. The use of these tools is generally known as visual programming. Other manufacturers also develop these types of tools and libraries, like Borland C++, Visual Age, etc...
During the 60s, while computers were still in an early stage of development, many new programming languages appeared. Among them, ALGOL 60, was developed as an alternative to FORTRAN but taking from it some concepts of structured programming which would later inspire most procedural languages, such as CPL and its successors (like C++). ALGOL 68 also directly influenced the development of data types in C. Nevertheless ALGOL was an non-specific language and its abstraction made it impractical to solve most commercial tasks.
In 1963 the CPL (Combined Programming language) appeared with the idea of being more specific for concrete programming tasks of that time than ALGOL or FORTRAN. Nevertheless this same specificity made it a big language and, therefore, difficult to learn and implement.
In 1967, Martin Richards developed the BCPL (Basic Combined Programming Language), that signified a simplification of CPL but kept most important features the language offered. Although it too was an abstract and somewhat large language.
In 1970, Ken Thompson, immersed in the development of UNIX at Bell Labs, created the B language. It was a port of BCPL for a specific machine and system (DEC PDP-7 and UNIX), and was adapted to his particular taste and necessities. The final result was an even greater simplification of CPL, although dependent on the system. It had great limitations, like it did not compile to executable code but threaded-code, which generates slower code in execution, and therefore was inadequate for the development of an operating system. Therefore, from 1971, Dennis Ritchie, from the Bell Labs team, began the development of a B compiler which, among other things, was able to generate executable code directly. This "New B", finally called C, introduced in addition, some other new concepts to the language like data types (char).
In 1973, Dennis Ritchie, had developed the basis of C. The inclusion of types, its handling, as well as the improvement of arrays and pointers, along with the later demonstrated capacity of portability without becoming a high-level language, contributed to the expansion of the C language. It was established with the book "The C Programming Language" by Brian Kernighan and Dennis Ritchie, known as the White Book, and that served as de facto standard until the publication of formal ANSI standard (ANSI X3J11 committee) in 1989.
In 1980, Bjarne Stroustrup, from Bell labs, began the development of the C++ language, that would receive formally this name at the end of 1983, when its first manual was going to be published. In October 1985, the first commercial release of the language appeared as well as the first edition of the book "The C++ Programming Language" by Bjarne Stroustrup.
During the 80s, the C++ language was being refined until it became a language with its own personality. All that with very few losses of compatibility with the code with C, and without resigning to its most important characteristics. In fact, the ANSI standard for the C language published in 1989 took good part of the contributions of C++ to structured programming.
From 1990 on, ANSI committee X3J16 began the development of a specific standard for C++. In the period elapsed until the publication of the standard in 1998, C++ lived a great expansion in its use and today is the preferred language to develop professional applications on all platforms.
C++ has been evolving, and a new version of the standard, c++0x, is being developed to be published soon, with several new features.
Nowadays computers are able to perform many different tasks, from simple mathematical operations to sophisticated animated simulations. But the computer does not create these tasks by itself, these are performed following a series of predefined instructions that conform what we call a program.
A computer does not have enough creativity to make tasks which it has not been programmed for, so it can only follow the instructions of programs which it has been programmed to run. Those in charge of generating programs so that the computers may perform new tasks are known as programmers or coders, who for that purpose use a programming language.
Programming languages
A programming language is a set of instructions and a series of lexical conventions specifically designed to order computers what to do.
When choosing a programming language to make a project, many different considerations can be taken. First, one must decide what is known as the level of the programming language. The level determines how near to the hardware the programming language is. In the lower level languages, instructions are written thinking directly on interfacing with hardware, while in "high level" ones a more abstract or conceptual code is written.
Generally, high level code is more portable, that means it can work in more different machines with a smaller number of modifications, whereas a low level language is limited by the peculiarides of the hardware which it was written for. Nevertheless, the advantage of low level code is that it is usually faster due to the fact that it is indeed written taking advantage of the possibilities of a specific machine.
A higher or lower level of programming is to be chosen for a specific project depending on the type of program that is being developed. For example, when a hardware driver is developed for an operating system obviously a very low level is used for programming. While when big applications are developed usually a higher level is chosen, or a combination of critic parts written in low level languages and others in higher ones.
Although there are languages that are clearly thought to be low level, like Assembly, whose instruction sets are adapted to each machine the code is made for, and other languages are inherently high level, like the Java, that is designed to be totally independent of the platform where is going to run. The C++ language is in a middle position, since it can interact directly with the hardware almost with no limitations, and can as well abstract lower layers and work like one of the most powerful high level languages.
Why C++ is better than other languages?
C++ has certain characteristics over other programming languages. The most remarkable are:
Object-oriented programming
The possibility to orientate programming to objects allows the programmer to design applications from a point of view more like a communication between objects rather than on a structured sequence of code. In addition it allows a greater reusability of code in a more logical and productive way.
Portability
You can practically compile the same C++ code in almost any type of computer and operating system without making any changes. C++ is the most used and ported programming language in the world.
Brevity
Code written in C++ is very short in comparison with other languages, since the use of special characters is preferred to key words, saving some effort to the programmer (and prolonging the life of our keyboards!).
Modular programming
An application's body in C++ can be made up of several source code files that are compiled separately and then linked together. Saving time since it is not necessary to recompile the complete application when making a single change but only the file that contains it. In addition, this characteristic allows to link C++ code with code produced in other languages, such as Assembler or C.
C Compatibility
C++ is backwards compatible with the C language. Any code written in C can easily be included in a C++ program without making any change.
Speed
The resulting code from a C++ compilation is very efficient, due indeed to its duality as high-level and low-level language and to the reduced size of the language itself.
Overview:
Displays internet configuration, including IP address.
Tip: To display your IP address, simply type: ipconfig
Note: If you are using a router to connect to the internet, this command displays your local IP address. It does not display the IP address that the outside world sees. Instead, use getip or visit WhatIsMyIP.com or checkip.dyndns.org.
Command Options:
There are a few options you can use with the ipconfig command. For the complet list of options, type ipconfig /?
The following examples demonstrate some of the more useful options:
ipconfig
ipconfig /all
Displays information about all the network adapters. Add flag /all to display detailed information; otherwise, displays only the IP address, subnet mask and default gateway for each adapter bound to TCP/IP.
ipconfig /flushdns
Used to clear dns, that is, flush the local DNS resolver cache.
ipconfig /renew
Renews the IP address for all network adapters.
ipconfig /?
USAGE:
ipconfig [/? | /all | /renew [adapter] | /release [adapter] |
/flushdns | /displaydns | /registerdns |
/showclassid adapter |
/setclassid adapter [classid] ]
where
adapter Connection name
(wildcard characters * and ? allowed, see examples)
Options:
/? Display this help message
/all Display full configuration information.
/release Release the IP address for the specified adapter.
/renew Renew the IP address for the specified adapter.
/flushdns Purges the DNS Resolver cache.
/registerdns Refreshes all DHCP leases and re-registers DNS names
/displaydns Display the contents of the DNS Resolver Cache.
/showclassid Displays all the dhcp class IDs allowed for adapter.
/setclassid Modifies the dhcp class id.
The default is to display only the IP address, subnet mask and
default gateway for each adapter bound to TCP/IP.
For Release and Renew, if no adapter name is specified, then the IP address
leases for all adapters bound to TCP/IP will be released or renewed.
For Setclassid, if no ClassId is specified, then the ClassId is removed.
Examples:
> ipconfig ... Show information.
> ipconfig /all ... Show detailed information
> ipconfig /renew ... renew all adapters
> ipconfig /renew EL* ... renew any connection that has its
name starting with EL
> ipconfig /release *Con* ... release all matching connections,
eg. "Local Area Connection 1" or
"Local Area Connection 2"
Displays or changes file attributes.
Quick Guide:
Hide/Unhide a Directory:
attrib -h directory
For example, if c:\mystuff\secret\ is hidden then type: attrib -h c:\mystuff\secret\ to unhide it.
To reverse the change and make the directory hidden, type: attrib +h c:\mystuff\secret\
Hide/Unhide a File:
attrib -h filename
For example, if c:\mystuff\secret.txt is hidden then type: attrib -h c:\mystuff\secret.txt to unhide it.
To reverse the change and make the file hidden, type: attrib +h c:\mystuff\secret.txt
Command Variations:
attrib
attrib filename
Display attributes of all the files in the current directory or of only the specified file.
attrib +attribute filename
attrib -attribute filename
For the specified file, either sets (+) or clears (-) the specified attribute attribute:
Attribute Meaning
a Archive
h Hidden
r Read-only
s System
Multiple attributes can be specified at the same time, all as part of one attrib command. The order of the attributes does not matter. For example, to simultaneously clear the hidden attribute and set the read-only attribute of the file mystuff.txt, use: attrib -h +r mystuff.txt
Command Options:
The following examples demonstrate some of the more useful options of the attrib command. For the complet list of options, type attrib /? or help attrib
Hide/Unhide a Directory:
attrib -h directory
For example, if c:\mystuff\secret\ is hidden then type: attrib -h c:\mystuff\secret\ to unhide it.
To reverse the change and make the directory hidden, type: attrib +h c:\mystuff\secret\
Hide/Unhide a File:
attrib -h filename
For example, if c:\mystuff\secret.txt is hidden then type: attrib -h c:\mystuff\secret.txt to unhide it.
To reverse the change and make the file hidden, type: attrib +h c:\mystuff\secret.txt
Warning: This command is for advanced users only!
Deletes one or more files. The specified file (or files) is deleted immediately deleted without any confirmation.
Tip: It is recommended that you delete files using Windows rather than MS-DOS. If you do use the del command, it is recommeded that you use the /p parameter so that a confirmation prompt is displayed before doing the deletion, such as: del /? *.txt
Danger: Do not delete anything unless you know exactly what you are doing. MS-DOS does not have a "Recycle Bin" so you cannot recover files deleted with the "del" command.
Danger: The character * (an asterisk) is the wildcard character and allows you to delete all matching files by using one command, such as "del *.tmp" deletes all files that end with ".tmp" in their filename. All matching files are immediately deleted without any confirmation and cannot be recovered.
Danger: It is extremely dangerous to use "del *" since that would delete everything in the directory. In this one case, MS-DOS realizes the danger and prompts you to confirm.
help del
Deletes one or more files.
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names
names Specifies a list of one or more files or directories.
Wildcards may be used to delete multiple files. If a
directory is specified, all files within the directory
will be deleted.
/P Prompts for confirmation before deleting each file.
/F Force deleting of read-only files.
/S Delete specified files from all subdirectories.
/Q Quiet mode, do not ask if ok to delete on global wildcard
/A Selects files to delete based on attributes
attributes R Read-only files S System files
H Hidden files A Files ready for archiving
- Prefix meaning not
If Command Extensions are enabled DEL and ERASE change as follows:
The display semantics of the /S switch are reversed in that it shows
you only the files that are deleted, not the ones it could not find.
Overview:
Use the notepad command to run the Windows Notepad text editor program.
Command Variations:
notepad
This command will cause the Windows Notepad text editor program to be run. This program is the same Windows Notepad program that is accessible in Windows via: Start > Programs > Accessories > Notepad
notepad filename
This command will cause the file named filename to be opened by the Notepad text editor. For example, notepad mylist.txt would open the mylist.txt file. If the file filename does not exist, Notepad will ask you if you want to create a new file with that name.
If you want to edit a file that is in a directory other than the current directory, then use the "cd directory" command first or specify the directory name as part of the filename, such as: "notepad \mystuff\ebooks\list.txt". If the filename contains spaces, enclose the entire filename in quotation marks, such as: notepad "\mystuff\my downloads\list.txt"
Overview:
Use the dir command to display a listing of the contents of the current directory. Information about the files and subdirectories of the current directory will be displayed.
Command Variations:
dir directory
By specifying a directory, the contents of that directory is displayed. For example, dir \mystuff will display the contents of the \mystuff directory. Note: If directory contains a space, then type quotation marks around the directory name; for example, dir "c:\program files"
dir > myfiles.txt
Will save a list of all files contained in the current directory to the file myfiles.txt. You can use >filename at the end of any command to cause that command's output to be written to the file specified.
Tip: You can use the clip command to save the directory listing to the Windows clipboard, such as: dir | clip
Tip: If you want to save a list of files and their properties (e.g.: file size, last modified date) to a .csv spreadsheet file, try using the filelist utility.
dir *.txt
Displays a listing of all the .txt files located in the current (or specified) directory.
dir my*
Displays a listing of all files that start with the pattern you specify; in this example, "my".
Command Options:
There are a few options you can use with the dir command. For the complet list of options, type dir /? or help dir
Position of options: If you specify a directory as part of the command, options can be specified before or after directory
Multipel options: You can type more then one option at the same time. For example, dir /p/w \mystuff would display a wide listing of the \mystuff directory and pause after each screenful.
The following examples demonstrate some of the more useful options:
dir /p
Pause the directory listing after every screenful. To continue the listing, press any key (e.g.: spacebar or Enter key).
dir /o:gne
Displays a directory listing that is sorted. You specify the sort order by one or more letter after the /o: part. The most useful sort order is gne which puts all the subdirectories before files (g), and sorts by name (n), and then by filename ending (e).
Tip: You can set the sort order (remains in effect until you close the MS-DOS window) by typing a set command, such as: set dircmd=/o:gne
dir /o:s
Displays a directory listing that is sorted by size (smallest to largest). To reverse the sort order (largest size to smallest size), prefix the sort order with a - (minus sign): dir /o:-s
dir /o:d
Displays a directory listing that is sorted by date/time (oldest to newest; oldest at top, newest at bottom). To reverse the sort order (newest to oldest; newest at top, oldest at bottom), prefix the sort order with a - (minus sign): dir /o:-d
dir /s
Displays the contents of the current directory (or specified directory) as well as the contents of all subdirectories and their subdirectories too. Since the output can be very long, especially if you have subdirectories inside subdirectories, you probably should also use the /p option to pause output. If you forget to do that, you'll probably see the output zipping by on your screen; in that case, press Ctrl-C to stop the command. Or you might want to save the output to a text file, for example: dir /s > myfiles.txt will output a list of all files contained in the current directory and all subdirectories to the file myfiles.txt
dir /s *.txt
Displays a listing of all .txt files located in the current directory and in all subdirectories.
dir /s mystuff.txt
Displays a listing of all instances of a file named mystuff.txt located in the current directory and in all subdirectories. Useful when you know the name of a file but don't recall which subdirectory it is located in. You can think of this command as the equivalent of the Windows Search Companion (accessible by pressing F3 when viewing a Windows folder).
dir /w
Wide directory listing.
dir /b
Displays a directory listing showing just the filenames without header information or file size/date. This bare format is useful when you just want the actual filenames and you're going to do some sort of further processing. For example dir /b /s \mystuff > files.txt would create a file named files.txt that contains just the filenames of files located in the \mystuff directory and all its subdirectories.
dir /ah
Displays a listing of hidden files (if any) that are located in the directory. Tip: Use the attrib command to change the hidden attribute of a file.
Overview:
When you are using a Microsoft MS-DOS command window, MS-DOS works on one directory at a time. The "current" directory is indicated as part of the command prompt.
For example, the command prompt "C:\mystuff\ebooks>" means that the current directory is the "ebooks" directory which is located inside the "mystuff" directory on the c: drive.
Use the cd command to make a different directory the "current" directory ("cd" is short for "change directory").
The command can be typed as either:
cd directory
or
cd drive:directory
For example, "cd \mystuff" will make "\mystuff" the current directory. To get to the "root" (top level directory) of your c: drive, type cd \
If directory contains spaces, then enclose it with quotation marks. For example: cd "C:\Documents and Settings\CCC\My Documents\My Music" or cd "My Music"
Command Variations:
cd directory
cd drive:directory
Make the specified directory directory (or drive:directory) the current directory.
The directory can start with a \ or be relative to the current directory. For example, if the current directory is C:\mystuff then typing cd ebooks will change the current directory to C:\mystuff\ebooks (assuming that there is in fact a ebooks sub-directory inside C:\mystuff).
Note: Each drive (c:, d:, e:, etc.) has its own current directory. That's why there is the drive:directory variation of the cd command. For example: cd e:\photos will set the current directory of the e: drive to \photos. To switch to the e: drive, you would simply type e: and press the Enter key.
cd /d drive:directory
Make the specified directory directory the current directory and also switch do the drive: drive.
Tip: To make cd always do /d without you having to type it, create a command macro named cd by typing: doskey cd = cd /d $*
cd ..
You can also type cd .. (the two dots are required) to back out one level out of the current directory. For example, if the current directory is C:\mystuff\ebooks then typing cd .. will change the current directory to C:\mystuff
cd
If you type cd without specifying a directory, the cd command will display the directory path of the current directory. Typically you will not use this variation of the cd command since the directory path is shown in the command prompt. It is more useful in batch files.
The below steps will teach you how to open MS DOS command prompt in any Windows OS. MS DOS is a command prompt of Microsoft Corporation and can be used a as an OS in its own way!
Run cmd.exe or command.exe
To open a Microsoft MS-DOS command prompt shell window, first click the Windows Start menu (located at the very lower-left corner of your computer's desktop) and select "Run...".
Then if you are using Windows XP or Vista or Windows 7, type cmd into the Run box and click "OK". You could also type cmd.exe
Otherwise, if you are using an older version of Windows, type command into the Run box and click "OK". You could also type command.exe
After you click "OK", an MS-DOS command prompt window will appear. Depending upon which version of Windows you are using, the MS-DOS command window will look similar to these images:


The standard window displays white text on a black background. This color combination may make text difficult to read. To make the window display black text on a white background, type the command: color f0 (that's the letter f followed by the digit zero 0). To go back to the standard of white text on a black background, type: color
Hello Friends,
The below is a list of all commands of MS-DOS. The list is totally complete with all the commands and gives you complete info of each and every command with syntax.
(External)
APPEND ;
APPEND [d:]path[;][d:]path[...]
APPEND [/X:on|off][/path:on|off] [/E]
Displays or sets the search path for data files. DOS will search the specified path(s) if the file is not found in the current path.
(External)
ASSIGN x=y [...] /sta
Redirects disk drive requests to a different drive.
(External)
ATTRIB [d:][path]filename [/S]
ATTRIB [+R|-R] [+A|-A] [+S|-S] [+H|-H] [d:][path]filename [/S]
Sets or displays the read-only, archive, system, and hidden attributes of a file or directory.
(External)
BACKUP d:[path][filename] d:[/S][/M][/A][/F:(size)] [/P][/D:date] [/T:time] [/L:[path]filename]
Makes a backup copy of one or more files. (In DOS Version 6, this program is stored on the DOS supplemental disk.)
(Internal)
BREAK =on|off
Used from the DOS prompt or in a batch file or in the CONFIG.SYS file to set (or display) whether or not DOS should check for a Ctrl + Break key combination.
(Internal)
BUFFERS=(number),(read-ahead number)
Used in the CONFIG.SYS file to set the number of disk buffers (number) that will be available for use during data input. Also used to set a value for the number of sectors to be read in advance (read-ahead) during data input operations.
(Internal)
CALL [d:][path]batchfilename [options]
Calls another batch file and then returns to current batch file to continue.
(Internal)
CHCP (codepage)
Displays the current code page or changes the code page that DOS will use.
(Internal)
CHDIR (CD) [d:]path
CHDIR (CD)[..]
Displays working (current) directory and/or changes to a different directory.
(External)
CHKDSK [d:][path][filename] [/F][/V]
Checks a disk and provides a file and memory status report.
(Internal)
CHOICE [/C[:]keys] [/N][/S][/T[:]c,nn] [text]
Used to provide a prompt so that a user can make a choice while a batch program is running.
(Internal)
CLS
Clears (erases) the screen.
(External)
COMMAND [d:][path] [device] [/P][/E:(size)] [/MSG][/Y [/C (command)|/K (command)]
Starts a new version of the DOS command processor (the program that loads the DOS Internal programs).
(External)
COMP [d:][path][filename] [d:][path][filename] [/A][/C][/D][/L][/N:(number)]
Compares two groups of files to find information that does not match. (See FC command).
(Internal)
COPY [/Y|-Y] [/A][/B] [d:][path]filename [/A][/B] [d:][path][filename] [/V]
or
COPY [/Y|-Y][/A][/B] [d:][path]filename+[d:][path]filename[...][d:][path][filename] [/V]
Copies and appends files.
(Internal)
COUNTRY=country code,
[code language="page"][/code]
[/code]
[,][d:][filename]
Used in the CONFIG.SYS file to tell DOS to use country-specific text conventions during processing.
(Internal)
CTTY (device)
Changes the standard I/O (Input/Output) device to an auxiliary device.
(Internal)
DATE mm-dd-yy
Displays and/or sets the system date.
(External)
DBLSPACE / automount=drives
DBLSPACE /chkdsk [/F] [d:]
DBLSPACE /compress d: [/newdrive=host:] [/reserve=size] [/F]
DBLSPACE /create d: [/newdrive=host:] [/reserve=size] [/size=size]
DBLSPACE /defragment [d:] ]/F]
DBLSPACE /delete d:
DBLSPACE /doubleguard=0|1
DBLSPACE /format d:
DBLSPACE [/info] [d:]
DBLSPACE /list
DBLSPACE /mount[=nnn] host: [/newdrive=d:]
DBLSPACE /ratio[=ratio] [d:] [/all]
DBLSPACE /size[=size] [/reserve=size] d:
DBLSPACE /uncompress d:
DBLSPACE /unmount [d:]
A program available with DOS 6.0 that allows you to compress information on a disk.
(External)
DEBUG [pathname] [parameters]
An MS-DOS utility used to test and edit programs.
(External)
DEFRAG [d:] [/F][/S[:]order] [/B][/skiphigh [/LCD|/BW|/GO] [/H]
DEFRAG [d:] [/V][/B][/skiphigh] [/LCD]|/BW|/GO] [/H]
Optimizes disk performance by reorganizing the files on the disk.
(Internal)
DEL (ERASE) [d:][path]filename [/P]
Deletes (erases) files from disk.
(External)
DELOLDOS [/B]
Deletes all files from previous versions of DOS after a 5.0 or 6.0 installation.
(External)
DELTREE [/Y] [d:]path [d:]path[...]
Deletes (erases) a directory including all files and subdirectories that are in it.
(Internal)
DEVICE=(driver name)
Used in the CONFIG.SYS file to tell DOS which device driver to load.
(Internal)
DEVICEHIGH=(driver name)
Like DEVICE, DEVICEHIGH is used in the CONFIG.SYS file to tell DOS which device driver software to use for devices; however, this option is used to install the device driver into the upper memory area.
(Internal)
DIR [d:][path][filename] [/A:(attributes)] [/O:(order)] [/B][/C][/CH][/L][/S][/P][/W]
Displays directory of files and directories stored on disk.
(External)
DISKCOMP [d:] [d:][/1][/8]
Compares the contents of two diskettes.
(External)
DISKCOPY [d:] [d:][/1][/V][/M]
Makes an exact copy of a diskette.
(Internal)
DOS=[high|low],[umb|noumb]
Used in the CONFIG.SYS file to specify the memory location for DOS. It is used to load DOS into the upper memory area and to specify whether or not the upper memory blocks will be used.
(External)
DOSKEY [reinstall] [/bufsize=size][/macros][/history][/insert|/overstrike] [macroname=[text]]
Loads the Doskey program into memory which can be used to recall DOS commands so that you can edit them.
(External)
DOSSHELL [/B] [/G:[resolution][n]]|[/T:[resolution][n]]
Initiates the graphic shell program using the specified screen resolution.
(Internal)
DRIVPARM= /D:(number) [/C] [/F:(form factor)] [/H:(number)] [/I][ /N][/S:(number)] [/T:(tracks)]
Used in the CONFIG.SYS file to set parameters for a disk drive.
(Internal)
ECHO on|off
ECHO (message)
Displays messages or turns on or off the display of commands in a batch file.
(External)
EDIT [d:][path]filename [/B][/G][/H][/NOHI]
Starts the MS-DOS editor, a text editor used to create and edit ASCII text files.
(External)
EMM386 [on|off|auto] [w=on|off]
Enables or disables EMM386 expanded-memory support on a computer with an 80386 or higher processor.
(External)
EXE2BIN [d:][path]filename [d:][path]filename
Converts .EXE (executable) files to binary format.
(Internal)
EXIT
Exits a secondary command processor.
(External)
EXPAND [d:][path]filename [[d:][path]filename[ . . .]]
Expands a compressed file.
(External)
FASTHELP [command][command] /?
Displays a list of DOS commands with a brief explanation of each.
(External)
FASTOPEN d:[=n][/X]
Keeps track of the locations of files for fast access.
(External)
FC [/A][/C][/L][/Lb n][/N][/T][/W][number] [d:][path]filename [d:][path]filename
or (for binary comparisons)
FC [/B][/number] [d:][path]filename [d:][path]filename
Displays the differences between two files or sets of files.
(Internal)
FCBS=(number)
Used in the CONFIG.SYS file to specify the number of file-control blocks for file sharing.
(External)
FDISK [/status]
Prepares a fixed disk to accept DOS files for storage.
(Internal)
FILES=(number)
Used in the CONFIG.Sys file to specify the maximum number of files that can be open at the same time.
(External)
FIND [/V][/C][/I][/N] ÒstringÓ [d:][path]filename[...]
Finds and reports the location of a specific string of text characters in one or more files.
(Internal)
FOR %%(variable) IN (set) DO (command)
or (for interactive processing)
FOR %(variable) IN (set) DO (command)
Performs repeated execution of commands (for both batch processing and interactive processing).
(External)
FORMAT d:[/1][/4][/8][/F:(size)] [/N:(sectors)] [/T:(tracks)][/B|/S][/C][/V:(label)] [/Q][/U][/V]
Formats a disk to accept DOS files.
(Internal)
GOTO (label)
Causes unconditional branch to the specified label.
(External)
GRAFTABL [(code page)]
GRAFTABL [status]
Loads a table of character data into memory (for use with a color/graphics adapter).
(External)
GRAPHICS [printer type][profile] [/B][/R][/LCD][/PB:(id)] [/C][/F][/P(port)]
Provides a way to print contents of a graphics screen display.
(External)
HELP [command] [/B][/G][/H][/NOHI]
Displays information about a DOS command.
(Internal)
IF [NOT] EXIST filename (command) [parameters]
IF [NOT] (string1)==(string2) (command) [parameters]
IF [NOT] ERRORLEVEL (number) (command) [parameters]
Allows for conditional operations in batch processing.
(Internal)
INCLUDE= blockname
Used in the CONFIG.SYS file to allow you to use the commands from one CONFIG.SYS block within another.
(Internal)
INSTALL=[d: ][\path]filename [parameters]
Used in the CONFIG.SYS file to load memory-resident programs into conventional memory.
(External)
INTERLINK [client[:]=[server][:]]
Connects two computers via parallel or serial ports so that the computers can share disks and printer ports.
(External)
INTERSVR [d:][...][/X=d:][...] [/LPT:[n|address]] [/COM:[n|address]][/baud:rate] [/B][/V]
INTERSVR /RCOPY
Starts the Interlink server.
(External)
JOIN d: [d:path]
JOIN d: [/D]
Allows access to the directory structure and files of a drive through a directory on a different drive.
(External)
KEYB [xx][,][yyy][,][d:][path]filename [/E][/ID:(number)]
Loads a program that replaces the support program for U. S. keyboards.
(External)
LABEL [d:][volume label]
Creates or changes or deletes a volume label for a disk.
(Internal)
LASTDRIVE=(drive letter)
Used in the CONFIG.SYS file to set the maximum number of drives that can be accessed.
(Internal)
LOADFIX [d:][path]filename [parameters]
Ensures that a program is loaded above the first 64K of conventional memory, and runs the program.
(Internal)
LOADHIGH (LH) [d:][path]filename [parameters]
Loads memory resident application into reserved area of memory (between 640K-1M).
(External)
MEM [/program|/debug|/classify|/free|/module(name)] [/page]
Displays amount of installed and available memory, including extended, expanded, and upper memory.
(External)
MEMMAKER [/B][/batch][/session][/swap:d] [/T][/undo][/W:size1,size2]
Starts the MemMaker program, a program that lets you optimize your computer's memory.
(Internal)
MENUCOLOR=textcolor,[background]
Used in the CONFIG.SYS file to set the colors that will be used by DOS to display text on the screen.
(Internal)
MENUDEFAULT=blockname, [timeout]
Used in the CONFIG.SYS file to set the startup configuration that will be used by DOS if no key is pressed within the specified timeout period.
(Internal)
MENUITEM=blockname, [menutext]
Used in the CONFIG.SYS file to create a start-up menu from which you can select a group of CONFIG.SYS commands to be processed upon reboot.
(External)
MIRROR [d:]path [d:] path [...]
MIRROR [d1:][d2:][...] [/T(drive)(files)] [/partn][/U][/1]
Saves disk storage information that can be used to recover accidentally erased files.
(MD) (Internal)
MKDIR (MD) [d:]path
Creates a new subdirectory.
(External)
MODE n
MODE LPT#[:][n][,][m][,][P][retry]
MODE [n],m[,T]
MODE (displaytype,linetotal)
MODE COMn[:]baud[,][parity][,][databits][,][stopbits][,][retry]
MODE LPT#[:]=COMn [retry]
MODE CON[RATE=(number)][DELAY=(number)]
MODE (device) CODEPAGE PREPARE=(codepage) [d:][path]filename
MODE (device) CODEPAGE PREPARE=(codepage list) [d:][path]filename
MODE (device) CODEPAGE SELECT=(codepage)
MODE (device) CODEPAGE [/STATUS]
MODE (device) CODEPAGE REFRESH
Sets mode of operation for devices or communications.
(External)
MORE < (filename or command)
(name)|MORE
Sends output to console, one screen at a time.
(Internal)
MOVE [/Y|/-Y] [d:][path]filename[,[d:][path]filename[...]] destination
Moves one or more files to the location you specify. Can also be used to rename directories.
(External)
MSAV [d:] [/S|/C][/R][/A][/L][/N][/P][/F][/video][/mouse]
MSAV /video
Scans your computer for known viruses.
(External)
MSBACKUP [setupfile] [/BW|/LCD|/MDA]
Used to backup or restore one or more files from one disk to another.
(External)
MSCDEX /D:driver [/D:driver2. . .] [/E][/K][/S][/V][/L:letter] [/M:number]
Used to gain access to CD-ROM drives (new with DOS Version 6).
(External)
MSD [/B][/I]
MSD [/I] [/F[d:][path]filename [/P[d:][path]filename [/S[d:][path]filename
Provides detailed technical information about your computer.
(External)
NLSFUNC [d:][path]filename
Used to load a file with country-specific information.
(Internal)
NUMLOCK=on|off
Used in the CONFIG.SYS file to specify the state of the NumLock key.
(Internal)
PATH;
PATH [d:]path[;][d:]path[...]
Sets or displays directories that will be searched for programs not in the current directory.
(Internal)
PAUSE [comment]
Suspends execution of a batch file until a key is pressed.
(External)
POWER [adv:max|reg|min]|std|off]
Used to turn power management on and off, report the status of power management, and set levels of power conservation.
(External)
PRINT [/B:(buffersize)] [/D:(device)] [/M:(maxtick)] [/Q:(value] [/S:(timeslice)][/U:(busytick)] [/C][/P][/T] [d:][path][filename] [...]
Queues and prints data files.
(Internal)
PROMPT [prompt text] [options]
Changes the DOS command prompt.
(External)
RECOVER [d:][path]filename
RECOVER d:
Resolves sector problems on a file or a disk. (Beginning with DOS Version 6, RECOVER is no longer available ).
(Internal)
REM [comment]
Used in batch files and in the CONFIG.SYS file to insert remarks (that will not be acted on).
(Internal)
RENAME (REN) [d:][path]filename [d:][path]filename
Changes the filename under which a file is stored.
(External)
REPLACE [d:][path]filename [d:][path] [/A][/P][/R][/S][/U][/W]
Replaces stored files with files of the same name from a different storage location.
(External)
RESTORE d: [d:][path]filename [/P][/S][/B:mm-dd-yy] [/A:mm-dd-yy][/E:hh:mm:ss] [/L:hh:mm:ss] [/M][/N][/D]
Restores to standard disk storage format files previously stored using the BACKUP command.
(Internal)
RMDIR (RD) [d:]path
Removes a subdirectory.
(External)
SCANDISK [d: [d: . . .]|/all][/checkonly|/autofix[/nosave]|/custom][/surface][/mono][/nosummay]
SCANDISK volume-name[/checkonly|/autofix[/nosave]|/custom][/mono][/nosummary]
SCANDISK /fragment [d:][path]filename
SCANDISK /undo [undo-d:][/mono]
Starts the Microsoft ScanDisk program which is a disk analysis and repair tool used to check a drive for errors and correct any problems that it finds.
(External)
SELECT [d:] [d:][path] [country code][keyboard code]
Formats a disk and installs country-specific information and keyboard codes (starting with DOS Version 6, this command is no longer available).
(Internal)
SET (string1)=(string2)
Inserts strings into the command environment. The set values can be used later by programs.
(External)
SETVER [d:]:path][filename (number)][/delete][/quiet]
Displays the version table and sets the version of DOS that is reported to programs.
(External)
SHARE [/F:space] [/L:locks]
Installs support for file sharing and file locking.
(Internal)
SHELL=[d:][path]filename [parameters]
Used in the CONFIG.SYS file to specify the command interpreter that DOS should use.
(Internal)
SHIFT
Increases number of replaceable parameters to more than the standard ten for use in batch files.
(External)
SORT [/R][/+n] < (filename)
SORT [/R][/+n] > (filename2)
Sorts input and sends it to the screen or to a file.
(Internal)
STACKS=(number),(size)
Used in the CONFIG.SYS file to set the number of stack frames and the size of each stack frame.
(Internal)
SUBMENU=blockname, [menutext]
Used in the CONFIG.SYS file to create a multilevel menu from which you can select start-up options.
(External)
SUBST d: d:path
SUBST d: /D
Substitutes a virtual drive letter for a path designation.
(Internal)
SWITCHES= [/K][/F][/N][/W]
Used in the CONFIG.SYS file to configure DOS in a special way; for example, to tell DOS to emulate different hardware configurations.
(External)
SYS
[source][/source]
[/source]
d:
Transfers or copies the operating system files to another disk.
(Internal)
TIME hh:mm[:ss][.cc][A|P]
Displays current time setting of system clock and provides a way for you to reset the time.
(External)
TREE [d:][path] [/A][/F]
Displays directory paths and (optionally) files in each subdirectory.
(Internal)
TYPE [d:][path]filename
Displays the contents of a file.
(External)
UNDELETE [d:][path][filename] [/DT|/DS|/DOS]
UNDELETE [/list|/all|/purge[d:]|/status|/load|/U|/S[d:]|/Td:[-entries]]
Restores files deleted with the DELETE command.
(External)
UNFORMAT d: [/J][/L][/test][/partn][/P][/U]
Used to undo the effects of formatting a disk.
(Internal)
VER
Displays the DOS version number.
(Internal)
VERIFY on|off
Turns on the verify mode; the program checks all copying operations to assure that files are copied correctly.
(Internal)
VOL [d:]
Displays a disk's volume label.
(External)
VSAFE [/option[+|-]...] [/NE][/NX][Ax|/Cx] [/N][/D][/U]
VSAFE is a memory-resident program that continuously monitors your computer for viruses and displays a warning when it finds one.
(External)
XCOPY [d:][path]filename [d:][path][filename] [/A][/D:(date)] [/E][/M][/P][/S][/V][/W][Y\-Y]
Copies directories, subdirectories, and files.
To be functional, each DOS command must be entered in a particular way. This command entry structure is known as the command's "syntax." The syntax "notation" is a way to reproduce the command syntax in print. Think of syntax as pronouncing the command or language, but in writing.
For example, you can determine the items that are optional, by looking for information that is printed inside square brackets. The notation [d:], for example, indicates an optional drive designation. The command syntax, on the other hand, is how you enter the command to make it work.
1. Command Name
The DOS command name is the name you enter to start the DOS program (a few of the DOS commands can be entered using shortcut names). The DOS command name is always entered first. In this book, the command is usually printed in uppercase letters, but you can enter command names as either lowercase or uppercase or a mix of both.
2. Space
Always leave a space after the command name.
3. Drive Designation
The drive designation (abbreviated in this book as "d:") is an option for many DOS commands. However, some commands are not related to disk drives and therefore do not require a drive designation. Whenever you enter a DOS command that deals with disk drives and you are already working in the drive in question, you do not have to enter the drive designator. For example, if you are working in drive A (when the DOS prompt A> is showing at the left side of the screen) and you want to use the DIR command to display a directory listing of that same drive, you do not have to enter the drive designation. If you do not enter a drive designation, DOS always assumes you are referring to the drive you are currently working in (sometimes called the "default" drive).
4. A Colon
When referring to a drive in a DOS command, you must always follow the drive designator with a colon (:) (this is how DOS recognizes it as a drive designation).
5. Pathname
A pathname (path) refers to the path you want DOS to follow in order to act on the DOS command. As described in Chapter 3, it indicates the path from the current directory or subdirectory to the files that are to be acted upon.
6. Filename
A filename is the name of a file stored on disk. As described in Chapter 1, a filename can be of eight or fewer letters or other legal characters.
7. Filename Extension
A filename extension can follow the filename to further identify it. The extension follows a period and can be of three or fewer characters. A filename extension is not required.
8. Switches
Characters shown in a command syntax that are represented by a letter or number and preceded by a forward slash (for example, "/P") are command options (sometimes known as "switches"). Use of these options activate special operations as part of a DOS command's functions.
9. Brackets
Items enclosed in square brackets are optional; in other words, the command will work in its basic form without entering the information contained inside the brackets.
10. Ellipses
Ellipses (...) indicate that an item in a command syntax can be repeated as many times as needed.
11. Vertical Bar
When items are separated by a vertical bar (|), it means that you enter one of the separated items. For example: ON | OFF means that you can enter either ON or OFF, but not both.
MS-DOS (Microsoft Disk Operating System) was the Microsoft-marketed version of the first widely-installed operating system in personal computers. It was essentially the same operating system that Bill Gates's young company developed for IBM as Personal Computer - Disk Operating System (PC-DOS). Most users of either DOS system simply referred to their system as Disk Operating System. Like PC-DOS, MS-DOS was (and still is) a non-graphical line-oriented command-driven operating system, with a relatively simple interface but not overly "friendly" user interface. Its prompt to enter a command looks like this:
The first Microsoft Windows operating system was really an application that ran on top of the MS-DOS operating system. Today, Windows operating systems continue to support DOS (or a DOS-like user interface) for special purposes by emulating the operating system.
In the 1970s before the personal computer was invented, IBM had a different and unrelated DOS that ran on smaller business computers. It was replaced by IBM's VSE operating system.
A search box is provided on their home page. Search for your desired domain name and select the extension (.com, .net etc.)
If it is available, push "Continue to Registration."
Select how many years you would like to own your domain name. You will be able to renew your domain name later if you choose.
You will be given options to purchase e-mail addresses and web hosting. These are not essential when purchasing your domain name. But, you will need someone to host your domain name when you are ready to publish material on your site. Web Hosting can be added at a later date. Select "Checkout."
Select payment method and purchase your domain name