You Are Reading

0

C++ Lecture: 1

Unknown Saturday 7 July 2012 ,
           Lecture: 1
First C++ program
The best way to learn C is to start coding right away. So here is our very first program in C.

Code:

#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
       cout << “ Welcome to Virtual University of Pakistan” << endl;
       getch();
       return 0;
 }

Explain the code:
1)   #include: This is a pre-processor directive. This is the name of the library definition file for all Input Output Streams. Your program will almost certainly want to send stuff to the screen and read things from the keyboard. “iostream” is the name of the file in which has code to do that work for you.
2)   In header file consol input output in our programs.
3)   A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers or symbols.
4)   C regards the name "main" as a special case and will run this function first.
“int” is a data type. It is a return type in main function. There are parentheses (“( )”, normal brackets) with main. Here the parentheses contain with in pass the argument.
The two type of argument one of integer type and second of character type of argument.
5)   There is a curly bracket. It is a start main function and the body of main function.
6)   This is known as out put stream in C and C++. The sign << indicates the direction of data. The thing between the double quotes (“ ”) is known as character string. There is a semicolon (;) at the end of the above statement. The mean is endl or “\n” end of line in console.
7)   The function getche() (get character with echo) is declared in conio.h file.
8)   It is a return value in main function.
9)   There is a curly bracket. It is an end main function and the body of main function.
Code view in dev compiler:
Compile the program Ctrl+F9
Status: Done
Close the compile progress window and then run program Ctrl+F10. The output is program in console. The any key press closes the console window and moves the dev editor.

0 comments:

Post a Comment

 
Copyright 2010 Learn Dev C++