Lecture notes on


Syntax: : : variable –name; Example: #include int m=10; main()



Download 232,82 Kb.
bet11/45
Sana07.07.2022
Hajmi232,82 Kb.
#755880
1   ...   7   8   9   10   11   12   13   14   ...   45
Bog'liq
285 OOPS lecture notes Complete-конвертирован

Syntax: : : variable –name;


Example:

#include int m=10; main()


{
int m=20;
{
int k=m; int m=30;
cout<<”we are in inner block”; cout<<"k="<cout<<"m="<cout<<":: m="<<:: m<
}
cout<<”\n we are in outer block \n”; cout<<"m="<cout<<":: m="<<:: m<
}
Memory Management Operator
C uses malloc and calloc functions to allocate memory dynamically at run time . Similarly it uses the functions Free( ) to free dynamically allocated memory. We use dynamic allocation techniques when it is not known in advance how much of memory space as needed .


C++ also support those functions it also defines two unary operators new and delete that perform the task of allocating and freeing the memory in a better and easier way.


The new operator can be used to create objects of any type. Syntax: pointer- variable =new datatype;

Example:


p=new int; q=new int;

Where p is a pointer of type int and q is a pointer of type float.




int *p=new int; float *p=newfloat;


Subsequently, the statements

*p=25;
*q=7.5;


Assign 25 to the newly created int object and 7.5 to the float object.We can also initialize the memory using the new operator.


Syntax:

int *p=ne\v int(25);


float *q =new float(7.5);
new can be used to create a memory space for any data type including user defined such as arrays,structures,and classes .The general form for a one-dimensional array is:


pointer-variable =new data types [size];


creates a memory space for an array of 10 integers.


If a data object is no longer needed, it is destroyed to release the memory space for reuse.





Download 232,82 Kb.

Do'stlaringiz bilan baham:
1   ...   7   8   9   10   11   12   13   14   ...   45




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish