Вы находитесь на странице: 1из 10

HACKERRANK NOTES :-

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
A pointer in C is a way to share a memory address among
different contexts (primarily functions). They are primarily
used whenever a function needs to modify the content of a
variable, of which it doesn't have ownership.
Abstract base classes in C++ can only be used as base
classes. Thus, they are allowed to have virtual member
functions without definitions.

A cache is a component that stores data so future


requests for that data can be served faster. The data
stored in a cache might be the results of an earlier
computation, or the duplicates of data stored elsewhere. A
cache hit occurs when the requested data can be found in
a cache, while a cache miss occurs when it cannot. Cache
hits are served by reading data from the cache which is
faster than recomputing a result or reading from a slower
data store. Thus, the more requests that can be served
from the cache, the faster the system performs.

One of the popular cache replacement policies is: "least


recently used" (LRU). It discards the least recently used
items first.

For example, if a cache with a capacity to store 5 keys has


the following state(arranged from most recently used key
to least recently used key) -

53214
Now, If the next key comes as 1(which is a cache hit),
then the cache state in the same order will be -

15324
Now, If the next key comes as 6(which is a cache miss),
then the cache state in the same order will be -
61532
You can observe that 4 has been discarded because it
was the least recently used key and since the capacity of
cache is 5, it could not be retained in the cache any
longer.

stringstream is a stream class to operate on strings. It


basically implements input/output operations on memory
(string) based streams. stringstream can be helpful in
different type of parsing. The following operators/functions
are commonly used here

Operator >> Extracts formatted data.


Operator << Inserts formatted data.
Method str() Gets the contents of underlying string device
object.
Method str(string) Sets the contents of underlying string
device object.
Its header file is sstream.

One common use of this class is to parse comma-


separated integers from a string (e.g., "23,4,56").
stringstream ss("23,4,56");
char ch;
int a, b, c;
ss >> a >> ch >> b >> ch >> c; // a = 23, b = 4, c = 56

The GNU Compiler Collection (GCC) is a suite of


C++ provides a nice alternative data type to
manipulate strings, and the data type is
conveniently called string. Some of its widely
used features are the following:

Declaration:

string a = "abc";
Size:

int len = a.size();


Concatenate two strings:
string a = "abc";
string b = "def";
string c = a + b; // c = "abcdef".
Accessing element:

string s = "abc";
char c0 = s[0]; // c0 = 'a'
char c1 = s[1]; // c1 = 'b'
char c2 = s[2]; // c2 = 'c'

s[0] = 'z'; // s = "zbc"


P.S.: We will use cin/cout to read/write a
string.open source compliers most commonly
used for compiling C and C++ programs.

struct is a way to combine multiple fields to


represent a composite data structure, which
further lays the foundation for Object Oriented
Programming. For example, we can store
details related to a student in a struct
consisting of his age (int), first_name (string),
last_name (string) and standard (int).

struct can be represented as

struct NewType {
type1 value1;
type2 value2;
.
.
.
typeN valueN;
};

Classes in C++ are user defined types declared


with keyword class that has data and functions
. Although classes and structures have the
same type of functionality, there are some basic
differences. The data members of a class are
private by default and the members of a
structure are public by default. Along with
storing multiple data in a common block, it also
assigns some functions (known as methods) to
manipulate/access them. It serves as the
building block of Object Oriented
Programming.

It also has access specifiers, which restrict the


access of member elements. The primarily used
ones are the following:

public: Public members (variables, methods)


can be accessed from anywhere the code is
visible.
private: Private members can be accessed only
by other member functions, and it can not be
accessed outside of class.
Class can be represented in the form of

class ClassName {
access_specifier1:
type1 val1;
type2 val2;
ret_type1 method1(type_arg1 arg1,
type_arg2 arg2,...)
...
access_specifier2:
type3 val3;
type4 val4;
ret_type2 method2(type_arg3 arg3,
type_arg4 arg4,...)
...
};
It's a common practice to make all variables
private, and set/get them using public
methods. For example:

class SampleClass {
private:
int val;
public:
void set(int a) {
val = a;
}
int get() {
return val;
}
};
We can store details related to a student in a
class consisting of his age (int), first_name
(string), last_name (string) and standard (int).

GCC supports several other programming


languages as well, including Objective-C,
Fortran, Java, Ada, Go, and BRIG (HSAIL). The
compilers are most commonly used on Unix-
based systems, but a Windows port, called
MiniGW, can be used as well.
GCC includes several different compilers:
 gcc: A C compiler
 g++: A C++ and Objective-C compiler
 gfortran: A Fortran compiler
 gcj: A Java compiler
 GNAT: An Ada compiler
 gccgo: A Go compiler
GCC's modular design also allows plugins to be installed to extend
functionality of the software. Additional functionality includes support
for programming languages that do not come with GCC.

One great feature of GCC is its ability to cross-compile programs for


different platforms. This means that, even though a developer uses
GCC on one platform, it may be compiled for another target platform.

GCC is one of the most common choices for compiling C and C++
programs on Unix-based systems. If you're developing for Linux, GCC
is a good go-to choice. It can also be used for Windows, but other
compilers are typically preferred, such as the compiler included
with Microsoft Visual Studio.

 Free, open source suite of compilers


 Supports several different front end languages
 Can cross-compile executables for different platforms

Вам также может понравиться