Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C++ Syntax Cheat Sheet , Cheat Sheet of C programming

Good cheat sheet about C++ Syntax

Typology: Cheat Sheet

2019/2020

Uploaded on 10/09/2020

ekaksha
ekaksha 🇺🇸

4.4

(30)

268 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C++ Syntax (Cheat Sheet)
------------------------
Terms in <> are tokens which describe generically what goes in there. All
other terms are literally themselves.
EXAMPLE: <name> = <expression> represents
x = 5 or
name = "John" + "Stewman"
Also, a <statement> can be a function call, an assignment statement, an
if or if-else statement, a while or do-while loop, a switch statement, a for loop, etc.
// comment
/* another comment */
bool int float char long short string // types
'a' 124 -25.0 1.33e5 "hello" true // literal constants (values)
+ - / * % // arithmetic operations
< <= > >= == != // comparison operations
&& || ! // boolean operations
<statement>; <statement>; ... // statements
#include < <library_name> > // include file directive
#include "stuff.h" // include header file directive
using namespace <name> // namespace directive
enum <name> { <value_name_list> }; // enumeration definition
<name>, <name>, <name>, ... // value name list
#define <name> <value> // defined constant compiler directive
const <type> <name> = <value>; // constant definition
<type> <name>, <name>, ... ; // object definition(s)
<type> <name> = <value>; // object definition and initialization
<type> <name> ( <value> ); // another object defn & initialization
<element_type> <name> [ <number_of_elements> ]; // array declaration
<type> <name> ( <formal_parameter_list> ); // function prototype
<type> <name>, <type> <name>, ... // formal parameter list
<type> <name> ( <formal_parameter_list> ) // function definition
{
<definitions>
<statements>
}
<function_name> ( <actual_parameters> ); // call to void function
// call to (or use of) function which returns a value
<name> = <function_name> ( <actual_parameters> );
<name>, <name>, ... // actual parameters
{ // block -- can replace ANY statement
<definitions> // has its own LOCAL SCOPE
<statements>
}
pf3

Partial preview of the text

Download C++ Syntax Cheat Sheet and more Cheat Sheet C programming in PDF only on Docsity!

C++ Syntax (Cheat Sheet)

Terms in <> are tokens which describe generically what goes in there. All other terms are literally themselves. EXAMPLE: = represents x = 5 or name = "John" + "Stewman" Also, a can be a function call, an assignment statement, an if or if-else statement, a while or do-while loop, a switch statement, a for loop, etc.

// comment /* another comment */

bool int float char long short string // types 'a' 124 -25.0 1.33e5 "hello" true // literal constants (values)

    • / * % // arithmetic operations < <= > >= == != // comparison operations && ||! // boolean operations

; ; ... // statements

#include < <library_name> > // include file directive #include "stuff.h" // include header file directive

using namespace // namespace directive

enum { <value_name_list> }; // enumeration definition

, , , ... // value name list

#define // defined constant compiler directive

const = ; // constant definition

, , ... ; // object definition(s)

= ; // object definition and initialization ( ); // another object defn & initialization

<element_type> [ <number_of_elements> ]; // array declaration

( <formal_parameter_list> ); // function prototype

, , ... // formal parameter list

( <formal_parameter_list> ) // function definition { }

<function_name> ( <actual_parameters> ); // call to void function

// call to (or use of) function which returns a value = <function_name> ( <actual_parameters> );

, , ... // actual parameters

{ // block -- can replace ANY statement // has its own LOCAL SCOPE }

= ; // assignment statement

cout << fixed setprecision(2) endl // output stream related terms

cin >> // input stream related terms

ifstream ("filename"); // declare and open input file stream ofstream ("filename"); // declare and open output file stream

<stream_name>.open( char * ) // open file with name in char array <stream_name>.close() // close a stream

<sting_name>.c_str() // convert string object to char array

if ( <boolean_expression> ) // if statement ;

if ( <boolean_expression> ) // if-else statement ; else ;

switch ( ) // switch statement { case : break; case : <statements break; default : }

while ( <boolean_expression> ) // while loop ;

do { // do-while loop } while ( <boolean_expression> );

for ( ; <continuation_expression>; <increment_statement>) ;

class <class_name> // class header (prototype) { public: <function_prototypes> protected: <function_prototypes> private: <function_prototypes> <data_attributes> };

<class_name>::<function_name> ( <parameter_list> ) // member function { // implementation }

<object_name>.<function_name>(<actual_parameters>); // member function call