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 →Arrays Introduction C++
An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier. For arrays of a known size, 10 in this case, use the following declaration: int arr[10]; //Declares an array named arr of size 10, i.e, you can store 10 integers. Note Unlike C, C++ allows dynamic allocation of arrays at runtime without special calls like malloc(). If n = 10 , int arr[n] will create an array with space
View Solution →Variable Sized Arrays
Consider an n - element array, a, where each index i in the array a contains a reference to an array of Ki integers (where the value Ki of varies from array to array). See the Explanation section below for a diagram. Given a , you must answer q queries. Each query is in the format i j, where i denotes an index in array a and j denotes an index in the array located at a[i] . For each query, find and print the value of element j in the array at location a[i] on a new line. Input Format
View Solution →Attribute Parser C++
This challenge works with a custom-designed markup language HRML. In HRML, each element consists of a starting and ending tag, and there are attributes associated with each tag. Only starting tags can have attributes. We can call an attribute by referencing the tag, followed by a tilde, '~' and the name of the attribute. The tags may also be nested. The opening tags follow the format: <tag-name attribute1-name = "value1" attribute2-name = "value2" ...> The closing tags follow the format
View Solution →