C++ Functions, Libaries & Syntax Reference Guide

A complete, categorized reference of C++ syntax, functions, and programming structures for efficient coding, debugging, and software development

C++ Data Types & Variables

KeywordDescriptionExample
intStores integer values.int age = 25;
floatStores decimal values with single precision.float pi = 3.14f;
doubleStores decimal values with double precision.double g = 9.81;
charStores a single character.char grade = 'A';
stringStores text (requires <string> library).string name = "John";
boolStores true/false values.bool isReady = true;

C++ Control Structures

StructureDescriptionExample
if / elseExecutes code based on condition.if(x > 0) cout << "Positive"; else cout << "Negative";
switchSelects code to execute based on expression value.switch(day) { case 1: cout << "Mon"; break; }
forRepeats code a fixed number of times.for(int i=0;i<5;i++) cout << i;
whileRepeats code while condition is true.while(x < 10) x++;
do...whileExecutes code at least once, then checks condition.do { cout << x; } while(x<5);
break / continueBreaks or skips loop iteration.if(i==3) continue;

C++ Functions

ConceptDescriptionExample
Function DeclarationDefines the return type and parameters.int add(int a, int b);
Function DefinitionImplements function logic.int add(int a,int b){return a+b;}
Inline FunctionSuggests compiler to expand function inline.inline int square(int x){return x*x;}
Default ArgumentsAssigns default parameter values.void greet(string name="Guest");
Function OverloadingMultiple functions with same name but different parameters.int area(int r); double area(double r);
RecursionFunction calls itself.int fact(int n){return n==0?1:n*fact(n-1);}

C++ Object-Oriented Programming (OOP)

ConceptDescriptionExample
classDefines an object blueprint.class Car {public: void drive(){cout << "Go";}};
objectInstance of a class.Car myCar; myCar.drive();
constructorInitializes object data.Car(){cout << "Ready";}
inheritanceDerives a class from another.class EV : public Car { };
polymorphismAllows one interface for multiple forms.virtual void start(){}
encapsulationBundles data and methods together.private int speed;

Common C++ Standard Libraries

LibraryPurposeExample
<iostream>Input and output stream handling.cout << "Hello";
<cmath>Mathematical functions.pow(2,3);
<string>String manipulation.string s = "EngLab";
<vector>Dynamic array structure.vector<int> v = {1,2,3};
<algorithm>Sorting, searching, and data manipulation algorithms.sort(v.begin(), v.end());
<fstream>File input/output operations.ofstream file("data.txt");

About C++ Functions, Syntax & Programming

This C++ functions and syntax reference is a comprehensive, categorized guide for coding efficiently in C++ programming, software development, and engineering applications. It’s ideal for students, developers, engineers, and programmers who want to quickly learn, reference, and apply essential C++ functions, control structures, and OOP concepts to build reliable and maintainable software.


Applications


Look up C++ functions, libaries and syntax to improve coding efficiency, reduce errors and quickly find the C++ feature you require.

By learning and applying these C++ functions and programming structures, you can: