Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

drawbacks of traditional programming(procedural programming)

> Unmanageable programs


>problems in modification of data
>difficulties in implementtion
>focus on funvtion rather than data

c++ is obect oriented language

>focus on data rather than procedure


>progranms are divided into what are known as OBJECTS
>function that operate on the data of an object are tied together in the data
structure
>data is hidden n can not be accessed by external functions
>new data n function can be easily added whenever necessary

c++ was developed by bjarne stroustrup at AT & T bell laboratory of USA in 1983

#include<iostream>
using namespace std;
int cube(int t)
{
return t*t*t;
}
int main()
{
cout<<cube(5);
return 0;
}

#include<iostream>
using namespace std;
inline int cube(int t)
{
return t*t*t;
}
int main()
{
cout<<cube(5);
return 0;
}

inline keyword is the reqeust which may be accepted or not by the compiler is
depends on the rules

is just request not order

INLINE FUNCTION:

whwnever a function is called, it takes a lot of extra time in executing a series


of instruction for taskes such as-

jumping to the function


saving registers
puching argument into stack and
rerurning to the calling function

> above task will execute always, either the fun. is small r big
> when a funct. is mall therse task becaome overhead

> one solutiom to this prob is to use macro definition (macro like funtion).

Interview question
Q> what is the diff between macro funtion and inline funtion?

> c++ has a diff solution to this probln that is called inline funct

> an inline function is a funt that is exapnded in line when it is invoked. that
is, the compiler replaces the function call with the corresponding finction code

> to makea func. inline


code prorgram

> usually the function are made inline when they are small enough to be defined in
one or two lines
> remenmber that the inline keyword sends a request, not a commad , to the
compiler. the compiler may ignrethis request if the func definiton is too long& too
caomplivated. compiler will treat inline fun as a normal function.

#include<iostream>

macro function replace

when we use macro funtion expression is replace as it is and in inline firset solve
the expreession then givethe result

> some of the situations where inline expansion may not work
- if it has a loop, a switch, a goto
- if func containstatic variables
- if func is recursive

code optimize(better code)

//A program of making outsidefuntion function inline


#include<iostream>
using namspace std;
class abc
{
public:
void show();
};
inline void abc::show()
{
cout <<"Hello";
}
int main()
{
abc ol;
ol.show()
}

int main is the standard

Oops-
class(dtat type)
-data
1.static data
2.non static data
-function
1.static function
2.non static function

OR-

static
-data
1.static data
2.non static data
-function
1.static function
2.non static function
onject(instance/var)

in c and c++(function)
java onwards(method)

#include<iostream>
using namespace std;
class A
{
int a,b;
static int x,y;
};
int main()
{
A ob;
cout<<"Hello world";
return 0;
}

non static memeber is also known as instace memeber


static is also class member

{
int a,b,c; ]-instance
static int x,y ]-class
}

static is the shared(in visual basic)


static method one copy, one add fix

the data which is common for all or can say for all object then keep it static(give
it memory only one time dont kill memory space)

c++ only
class is blueprint not alllocated memory to its members
allocated memory to instace only so give class static memmber memory outside of the
class

#include<iostream>
using manespace std;

You might also like