Skip to main content

Posts

Showing posts from April, 2018

Variables

Variables:           A quantity whose value may change during execution of the program is called variable.It is represented by a symbol or a name Rules for writing variable names: The following are the rules for writing a variable name in a program in c++: The first character of variable name must be an alphabetic character.  Underscore can be used as first character of variable name. Blank spaces are not allowed in a variable name. Special character, such as arithmetic operators,#,^,cannot be used in a variable name. Reserved words cannot be used as variable names. The maximum length of a variable name depends upon the compiler of c++. A Variable name declared for one data-type cannot be used to declare another data-type. Example:  variables 'Pay' and 'pay' are two different variables.

Keyword

Keyword:             The words that are used by the language for special purpose are called keywords.These are also called reserved words For example:                  C++ programming the word main is used to indicate the starting of program ,include is used to add header files,int to declare an integer type variable. All these words are keywords of c++      The keywords cannot b used as variable names in a program.

C++ statements

C++ statements:                         The statements  of the program are written under the main () function between the curly braces {} . These statements are the body of the program. Each statements in c++ ends with a simicolon (;)          C++ is a case sensitive language. The c++ statements are normally written in lowercase letters but in some exceptional cases,these can also be written in uppercase.

The main() function

Main() function:                                 The main function indicates the beginning  of a c++ program. The statements within this function are the main body of the c++ program.If main() function is not included, the program is not compiled and an error message is generated. syntax:              main()             {                                                                  program statments........                          }

Header file

Header file:                   Header file is a c++ source file that contains defination of library functions/object.Header files are added into the program at the compilation of the program.             The Preprocessor directive"include" is used to add a header file into the program. syntax:             #include <name of the header file>

Writing c++ program

Introduction:                                       The source  code of a c++ program is stored on the disk with file extension cpp (cpp stands for  c plus plus) Structure of c++ programs:                                                       A c++ program consists of three main parts:  Preprocessor Directive     The main() function c++ statements Preprocessor Directives:                                         The instructions that are given to the compiler before the beginning of the actual program is called Preprocessor Directives also known  as compiler Directives Example:           #include<iostream> using namespace std; main() {    cout<<"<<Life is beautiful"; }