ITHelpself / CPlusPlus

0 stars 0 forks source link

1. getting started #1

Open ITHelpself opened 3 years ago

ITHelpself commented 3 years ago

#include <iostream>
int main()
{
 std::cout << "Hello World!" << std::endl;
}
ITHelpself commented 3 years ago

// single line comments


int main()
{
GoalKicker.com – C++ Notes for Professionals 4
 // This is a single-line comment.
 int a; // this also is a single-line comment
 int i; // this is another single-line comment
}
ITHelpself commented 3 years ago

// multi line comments


int main()
{
 /*
 * This is a block comment.
 */
 int a;
}
ITHelpself commented 3 years ago

int main()
{
 /* A block comment with the symbol /*
 Note that the compiler is not affected by the second /*
 however, once the end-block-comment symbol is reached,
 the comment ends.
 */
 int a;
}
ITHelpself commented 3 years ago

void SomeFunction(/* argument 1 */ int a, /* argument 2 */ int b);
ITHelpself commented 3 years ago

// function


int add2(int i); // The function is of the type (int) -> (int)
ITHelpself commented 3 years ago

// function


#include <iostream>
int add2(int i); // Declaration of add2
// Note: add2 is still missing a DEFINITION.
// Even though it doesn't appear directly in code,
// add2's definition may be LINKED in from another object file.
int main()
{
 std::cout << add2(2) << "\n"; // add2(2) will be evaluated at this point,
 // and the result is printed.
 return 0;
}
int add2(int i) // Data that is passed into (int i) will be referred to by the name i
{ // while in the function's curly brackets or "scope."

 int j = i + 2; // Definition of a variable j as the value of i+2.
 return j; // Returning or, in essence, substitution of j for a function call to
 // add2.
}
ITHelpself commented 3 years ago

// function overloading


int add2(int i) // Code contained in this definition will be evaluated
{ // when add2() is called with one parameter.
 int j = i + 2;
 return j;
}
int add2(int i, int j) // However, when add2() is called with two parameters, the
{ // code from the initial declaration will be overloaded,
 int k = i + j + 2 ; // and the code in this declaration will be evaluated
 return k; // instead.
}
ITHelpself commented 3 years ago

// default parameter


int multiply(int a, int b = 7); // b has default value of 7.
int multiply(int a, int b)
{
 return a * b; // If multiply() is called with one parameter, the
} // value will be multiplied by the default, 7.