BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan Right Header

Register FAQ Community Calendar New Posts Navbar Right Corner
HOME BZU Mail Box Online Games Radio and TV Cricket All Albums
Go Back   BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan > Institute of Computing > Bachelor of Science in Information Technology > BsIT 3rd Semester > Object Oriented Programming

Object Oriented Programming By Mam Sidra Malik


Reply
 
Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1  
Old 05-09-2008, 01:30 AM
.BZU.'s Avatar


 
Join Date: Sep 2007
Location: near Govt College of Science Multan Pakistan
Posts: 9,693
Contact Number: Removed
Program / Discipline: BSIT
Class Roll Number: 07-15
.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute.BZU. has a reputation beyond repute
lectures C++ References

C++ references allow you to create a second name for the a variable that you can use to read or modify the original data stored in that variable. While this may not sound appealing at first, what this means is that when you declare a reference and assign it a variable, it will allow you to treat the reference exactly as though it were the original variable for the purpose of accessing and modifying the value of the original variable--even if the second name (the reference) is located within a different scope. This means, for instance, that if you make your function arguments references, and you will effectively have a way to change the original data passed into the function. This is quite different from how C++ normally works, where you have arguments to a function copied into new variables. It also allows you to dramatically reduce the amount of copying that takes place behind the scenes, both with functions and in other areas of C++


Basic Syntax

Declaring a variable as a reference rather than a normal variable simply entails appending an ampersand to the type name, such as this "reference to an int"

Code:
int& foo = ....;


Did you notice the "...."? (Probably, right? After all, it's 25% of the example.) When a reference is created, you must tell it which variable it will become an alias for. After you create the reference, whenever you use the variable, you can just treat it as though it were a regular integer variable. But when you create it, you must intialize it with another variable, whose address it will keep around behind the scenes to allow you to use it to modify that variable.

In a way, this is similar to having a pointer that always points to the same thing. One key difference is that references do not require dereferencing in the same way that pointers do; you just treat them as normal variables. A second difference is that when you create a reference to a variable, you need not do anything special to get the memory address. The compiler figures this out for you:
Code:
int x; int& foo = x; // foo is now a reference to x so this sets x to 56 foo = 56; std::cout << x <<std::endl;


__________________
(¯`v´¯)
`*.¸.*`

¸.*´¸.*´¨) ¸.*´¨)
(¸.*´ (¸.
Bzu Forum

Don't cry because it's over, smile because it happened
Reply With Quote
  #2  
Old 06-09-2008, 05:02 AM
BSIT07-01's Avatar
Addicted to Computer


 
Join Date: Sep 2007
Location: ------------
Age: 34
Posts: 1,309
Contact Number: ---------------
Program / Discipline: BSIT
Class Roll Number: 07-01
BSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant future
Default Re: C++ References

Thanks,

But yeh tu buhut basic concept hay, pata nahi last day madam nay kya parhaya tha reference kay baray main. Mujhay tu kuchh samajh nai aai thi.
Reply With Quote
  #3  
Old 27-08-2011, 09:05 PM
Salman Mushtaq's Avatar

Feel The Difference



 
Join Date: Jul 2010
Location: Riyadh
Age: 33
Posts: 4,544
Contact Number: See my signature at the end of my posts
Program / Discipline: MIT
Class Roll Number: MITF12A006
Salman Mushtaq has a reputation beyond reputeSalman Mushtaq has a reputation beyond reputeSalman Mushtaq has a reputation beyond reputeSalman Mushtaq has a reputation beyond reputeSalman Mushtaq has a reputation beyond reputeSalman Mushtaq has a reputation beyond reputeSalman Mushtaq has a reputation beyond reputeSalman Mushtaq has a reputation beyond reputeSalman Mushtaq has a reputation beyond reputeSalman Mushtaq has a reputation beyond reputeSalman Mushtaq has a reputation beyond repute
Default Re: C++ References

C++ buhat asan language hai ,, lakin jab is main OOP k concepts atay hain tou sir ghoom jata hai ....,. IT series ki book main phir bhi kuch samaj a jata hai but english writters nay tou pata nahi khichri kar rakha hai ...
__________________

SALMAN MUSHTAQ

MOB:0333-7465571
Email: mani@bzupages.com
Note:
For Merit Lists click here !

Merit Lists of BZU
Merit List Distance Learning Education 2012
Reply With Quote
Reply

Tags
c++, lectures, references


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Best view in Firefox
Almuslimeen.info | BZU Multan | Dedicated server hosting
Note: All trademarks and copyrights held by respective owners. We will take action against any copyright violation if it is proved to us.

All times are GMT +5. The time now is 01:30 PM.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.