So here is the code for that program:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"My name is ABC"<<endl;
getch();
}
Explanation
- Line 1 & Line 2: We have included two header files in our program, those header files include some useful functions which will be used inside our code.
- Line 3: The brackets "()" at the end of third line indicate that it is a function. The code "void main()" has two parts:
void: means that this function doesn't return any value.
main: indicates that this is the main part of the object code. - Line 4: Starting curly bracket "{" indicates that this is the start of the function "void main()"
- Line 5: The function "clrscr()" clears the output-screen.
- Line 6: The keyword "cout" is used to display something as the output on the screen. Two left angle brackets "<<" concatenate or combine the two parts of a line of code. The words in double quotes "My name is ABC" are actually a string that is to be printed on screen. "endl" is a keyword in c++ that ends working on the current line and moves the cursor to next line.
- Line 7: "getch()" is a keyword in C++ which is used when we want the IDE to keep the program in running mode until the user gives a character (or simply, until the user presses any key on the keyboard). This helps us to keep the output steady on the user's screen until he/she presses a key.
- Line 8: Closing curly bracket "}" indicates that the function "void main()" has came to an end.
Output
The output of the above given program will look like this image:

No comments:
Post a Comment