You are on page 1of 4

21. Explain function prototype.

A function prototype is a definition that is used to perform type checking


on function call when the EGL system code does not have access to the
function itself . A function prototype begins with keyword function then
lists the function name its parameters (if any), and return value(if any).

Example :

Int add (int number 1,int number 2, int number 3);


Here in this function prototype we CAN easily understand that ;return
type of function =integer. Number of parameter=3.

22. Explain function overloading with suitable example.

Function overloading is a c++ programming feature that allows us to


have more than alone function having same name but different
parameter list,when I say parameter list , it means the datatype and
sequence of the parameter.

Note: In c++, many standard library functions are overloaded.

Example:

The sqrt() function can take double,float, int,etc. As parameters. This is


possible because the sqrt()function is overloaded in c++.

23. Explain structure with example.

 A structure is group of data element grouped together under one


name
 Unlike array, structure allow to combine data item types and
different length
 A structure is user defined data types
 Data item in a structure are called the member of the structure
 A structure creates a new type

Syntax:

Struct[structure name or tag]


sructure{
Member declaration;
Member declaration;
….
member declaration;
}[one or more structure variable ];

Example:

Here is the way the book structure will be declared


Struct books
{
char title[50];
Char author[50];
Char subject[100];
Int book id;
};

24.Explain class with example.

Class is a group of an object with the same properties and same


methods.

Example:

Class bicycle
{
Int cadence =0;
Int speed=0;
Int gear=1;
Void change cadence(int new value)
{
Cadence=new value;
}
Void change gear(int new value)
{
Gear= new value;
}
Void speedup(int increment)
{
Speed =speed+increment;
}
Void apply brakes (int decrement)
{
Speed=speed-decrement;
}

25.Give the difference between structure & class.

Structure in c++ Class in c++


A value data type that can hold A blueprint that defines data and
related data that belongs to methods to create object
various data types
Cannot inherit other classes Can inherit other classes or
structure
An instance is a structure variable An instance is an object
The keyword to define is “struct” The keyword to define “class”
If there are no access specifiers If there are no access specifiers
declared, then the member or the declared then the members are
properties are public private

26.Explain member function definition with example.

Member function are operator and functions that are declared as


members of a class. Member function do not include operators
and functions declared with the friend specifier. These are called
friends of a class. we can declare a member function as static ;
this is called a static member function.

Example:

Member function can be apply brakes,increase speed etc.

27. Explain static data member with characteristics with


example.

Static data member has the following properties:


 It is initialized by zero when first object of class I created.
 Only one copy of static data member is created for the entire
class and all object share the same
 Its scope is within class but its lifetime is entire program.

28. Explain static member function with example

A typically use of static member is for recording data common to


all object of a class

Example

You can use a static data member as a counter to store the


number of object of a particular class type that are created.

29. Explain friend function with characteristics and example

A friend access the private and protected data of the class . we


declare a friend function using the friend keyword inside the body
of the class

Characteristic:

I cannot be called using the object as it is not in the scope of the


class it can be invoked like a normal function without using the
object I cannot access the member name directly and has to use
an object name and dot membership operator with the member
number

Example:

Class demo
{
Int x;
Public:
Demo(int a)
{
X=a;
}
Friend void display
};

You might also like