When should i use references, and when ought to use pointers, C/C++ Programming

Assignment Help:

A: Use references when you can use, and use pointers when you have to.

References are generally preferred over pointers whenever you don't require "reseating". Usually this means that references are most useful in class's public interface. Typically references appear on the skin of an object, & pointers on the inside.

The exception to the above is where a function's parameter or return value require a "sentinel" reference a reference which does not refer to an object. Usually this is best done by returning/taking a pointer, & giving the NULL pointer this special significance (references must always alias objects, not dereferenced NULL pointer).

Note: Old line C programmers sometimes don't like references as they provide reference semantics which isn't explicit in the caller's code. However, after some C++ experience, one quickly realizes it is a form of information hiding, which is an asset instead of a liability. E.g., programmers must write code in the language of the problem instead of the language of the machine.

 


Related Discussions:- When should i use references, and when ought to use pointers

C++ Program Please see where i do mistake, #include #include #include ...

#include #include #include #include #include class Employee { private: char *Name; //Set them as pointers... int IdNumber; char *Department; char *Position; public: voi

Parking garage, A parking garage charges a $2.00 minimum fee to park for up...

A parking garage charges a $2.00 minimum fee to park for up to three hours and an additional $0.50 per hour for each hour or part thereof over three hours. The maximum charge for a

Define the multi dimensional arrays, Define the Multi Dimensional Arrays? ...

Define the Multi Dimensional Arrays? Consequently far we have considered arrays with only one dimension. It is as well possible to define an array which is having a 2-dimension

Strings, A string S is said to be "Super ASCII", if it contains the charact...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

Define the double data type of c language, Define the Double Data Type of c...

Define the Double Data Type of c Language? The double is used to define BIG floating point numbers and it reserves twice the storage for the number. When the accuracy provided

String storage within c, The concept of a string in C is difficult, because...

The concept of a string in C is difficult, because a string is a collection of characters stored in memory terminated by a NULL string i.e. \0. Let us consider the string Hello. Th

Strings, write a c program to find input string using strlen(), strcpy(), s...

write a c program to find input string using strlen(), strcpy(), strcat(),strncat(), strcmp().

Write a c program to input a floating point number, Step 1 Define the start...

Step 1 Define the start of the program    It should be noted that within C all commands should end in a semi-colon. For most of your programs the definition of a program header as

Structures of flowchart, Ask Draw a flowchart that print all even numbers f...

Ask Draw a flowchart that print all even numbers from 2 until 10

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd