الجمعة، 19 فبراير 2016

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++

The Basics of a C++ Program


•Function: collection of statements; when executed, accomplishes something
−May be predefined or standard
•Syntax: rules that specify which statements (instructions) are legal
•Programming language: a set of rules, symbols, and special words

•Semantic rule: meaning of the instruction


Comments
•Comments are for the reader, not the compiler
•Two types:
−Single line
// This is a C++ program. It prints the sentence:
−Multiple line
/*
   You can include comments that can
   occupy several lines.
*/
example :
#include <iostream>
using namespace std;
void main () 
{
//Cout<< "AL_Wessam";
cout<<"alwessam";
/*
cout << "a";
cout << "b";
cout << "c";

*/
}
Output after Run (alwessam)


Special Symbols


+       ?
  -       ,
  *      <=
  /      !=
  .      ==
  ;      >=


•Reserved words, keywords, or word symbols
−Include:
•int
•float
•double
•char
•const
•void
•return

Identifiers
•Consist of letters, digits, and the underscore character (_)
•Must begin with a letter or underscore
•C++ is case sensitive
−NUMBER is not the same as number
•Two predefined identifiers are cout and cin
•Unlike reserved words, predefined identifiers may be redefined, but it is not a good idea


The following are legal identifiers in C++:
−first
−conversion
−payRate


Whitespaces
•Every C++ program contains whitespaces
−Include blanks, tabs, and newline characters
•Used to separate special symbols, reserved words, and identifiers
•Proper utilization of whitespaces is important
−Can be used to make the program readable





ليست هناك تعليقات:

إرسال تعليق