Professional Documents
Culture Documents
Syntax For C++ Programming
Syntax For C++ Programming
Syntax For C++ Programming
C++ COMMENTS
Line comments
//put your comment here
Block Comments
/*
put your lines of comments here
you can put as many comments as possible
*/
DECLARING VARIABLES
1. Declaring and initializing a variable
variableType variableName = value; e.g int var1 = 10;
//if you want to display more than one variable use the following
cout<<"Put your text in here"<<variable_name1<<"your text here
"<<variable_name12<<endl;
THE INPUT STATEMENT
cin - sends a command to the computer to activate the cursor for user to
enter something
>> - extraction operator: it extract values from the keyboard
C++ OPERATORS
addition (+)
subtraction (-)
multiplication (*)
division (/) *note: this sign only returns the quotient after dividing two
numbers
division (%) *note: this sign only returns the remainder after dividing two
numbers
SYNTAX OF AN IF STATEMENTS
if(condition)
{
statements;
}
LOGICAL OPERATORS
while(condition)
{
statements;
}
2. while loop with initialization
initialization;
while(condtion)
{
statements;
increament;
}
if(condition1)
{
statements1;
}
else if(condition2)
{
statements2;
}
else if(conditionN)
{
statementsN;
}
else
{
statements;
}
switch(selector)
{
case Label1:
statements1;
break;
case Label2:
statements2;
break;
:
case LabelN:
statementsN;
break;
default:
statementsD;
}
FUNCTIONS
FUNCTION HEADERS
ReturnType functionName(parameters)
FUNCTION DEFINITION
ReturnType functionName (parameters)
{
statements;
}
FUNCTION CALL
variableName = function(valueParameters);
cout<<functionName(valueParameters)<<endl;
ARRAY DECLERATION
STRUCTS
struct structName
{
memberVariables;
};