0% found this document useful (0 votes)
238 views

Codearchery Notes

Functions allow programmers to organize code into reusable blocks that perform tasks. Functions are declared with a name, return type, and parameters. Function definitions provide the body of code. Functions can be overloaded with the same name but different parameters. Static variables maintain their value between function calls while automatic variables are destroyed after each call. Static member functions can be called without an object and are used to manipulate the class. Inheritance allows derived classes to inherit features from a base class.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
238 views

Codearchery Notes

Functions allow programmers to organize code into reusable blocks that perform tasks. Functions are declared with a name, return type, and parameters. Function definitions provide the body of code. Functions can be overloaded with the same name but different parameters. Static variables maintain their value between function calls while automatic variables are destroyed after each call. Static member functions can be called without an object and are used to manipulate the class. Inheritance allows derived classes to inherit features from a base class.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Function is a group of statements that together perform a task.

Every C++ program has at least one function, which is main (), and all the most trivial programs can
define additional functions. You can divide up your code into separate functions.

A function declaration tells the compiler about a function's name, return type, and parameters.

A function definition provides the actual body of the function. The C++ standard library provides
numerous built-in functions that your program can call.

A function prototype is a declaration of the function that tells the program about the type of the value
returned by the function and the number and type of arguments.

C++ provides an inline functions to reduce the function call overhead. Inline function is a function
that is expanded in line when it is called. When the inline function is called whole code of the inline
function gets inserted or substituted at the point of inline function call. If a function is inline, the
compiler places a copy of the code of that function at each point where the function is called at compile
time. Inline is just a request, not a command. The compiler decides whether the function is Inline or not.

Function overloading is a feature in C++ where two or more functions can have the same name but
different parameters. It can be considered as an example of polymorphism feature in C++.

In computer programming, a static variable is a variable that has been allocated "statically", meaning
that its lifetime (or "extent") is the entire run of the program. A static int variable remains in memory while
the program is running. A normal or auto variable is destroyed when a function call where the variable
was declared is over. For example, we can use static int to count number of times a function is called, but
an auto variable can't be used for this purpose.

By declaring a function member as static, you make it independent of any particular object of the class.
A static member function can be called even if no objects of the class exist and the static functions are
accessed using only the class name and the scope resolution operator.

Operator overloading is a type of polymorphism in which an operator is overloaded to give user


defined meaning to it and to perform operation on user-defined data type. This means C++ has the ability
to provide the operators with a special meaning for a data type, this ability is known as operator
overloading. It cannot be used for built-in types (int, float, char etc.). Two operators = and & are already
overloaded by default in C++. For example: To copy objects of same class, you can directly use =
operator.

Overloading unary operators Unary operator act upon a single operand to produce a new value.
Types of unary operators: unary minus (-); increment (++); decrement (- ... Unlike the operators you've
seen so far, the positive (+), negative (-) and logical not (!) operators all are unary operators.

C++ Constructors is a special type of member function that initializes an object automatically when it is
created. Compiler identifies a given member function is a constructor by its name and the return type.
Constructor has the same name as that of the class and it does not have any return type. If we do not
specify a constructor, C++ compiler generates a default constructor for us (expects no parameters and
has an empty body).

Inheritance allows software developers to derive a new class from the existing class. The derived class
inherits the features of the base class (existing class). 5 Types of Inheritance in C++ 1. Single, 2.
Multilevel, 3. Multiple, 4. Hierarchical and 5. Hybrid. Single Inheritance only one class can be derived
from the base class. Based on the visibility mode used or access specifier used while deriving, the
properties of the base class are derived. Access specifier can be private, protected or public. The
protected access specifier allows the class the member belongs to, friends, and derived classes to
access the member. However, protected members are not accessible from outside the class.

You might also like