Professional Documents
Culture Documents
Cppfourth (2 11 2023)
Cppfourth (2 11 2023)
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
INLINE 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
> 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>
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
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;
}
{
int a,b,c; ]-instance
static int x,y ]-class
}
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;