title-img


Basic Data Types C++

Some C++ data types, their format specifiers, and their most common bit widths are as follows: Int ("%d"): 32 Bit integer Long ("%ld"): 64 bit integer Char ("%c"): Character type Float ("%f"): 32 bit real value Double ("%lf"): 64 bit real value Reading To read a data type, use the following syntax: scanf("`format_specifier`", &val) For example, to read a character followed by a double: char ch; double d; scanf("%c %lf", &ch, &d); For the moment, we ca

View Solution →

Conditional Statements C++

if and else are two of the most frequently used conditionals in C/C++, and they enable you to execute zero or one conditional statement among many such dependent conditional statements. We use them in the following ways: 1. if: This executes the body of bracketed code starting with statement1 if condition evaluates to true. if (condition) { statement1; ... } 2. if - else: This executes the body of bracketed code starting with statement1 if condition evaluates to true, o

View Solution →

For Loop C++

A for loop is a programming language statement which allows code to be repeatedly executed. The syntax is for ( <expression_1> ; <expression_2> ; <expression_3> ) <statement> expression_1 is used for intializing variables which are generally used for controlling the terminating flag for the loop. expression_2 is used to check for the terminating condition. If this evaluates to false, then the loop is terminated. expression_3 is generally used to update the flags/varia

View Solution →

Functions C++

Functions are a bunch of statements glued together. A function is provided with zero or more arguments, and it executes the statements on it. Based on the return type, it either returns nothing (void) or something. The syntax for a function is return_type function_name(arg_type_1 arg_1, arg_type_2 arg_2, ...) { ... ... ... [if return_type is non void] return something of type `return_type`; } For example, a function to return the sum of four parameters can

View Solution →

Pointer C++

A pointer in C++ is used to share a memory address among different contexts (primarily functions). They are used whenever a function needs to modify the content of a variable, but it does not have ownership. In order to access the memory address of a variable, val , prepend it with & sign. For example, &val returns the memory address of val . This memory address is assigned to a pointer and can be shared among functions. For example, int* p = &val assigns the memory address of val to

View Solution →