sending a 'const char*' parameter to a function that recives 'const char* &'

why is this not OK?

void func(const char* &pointer){...}

//in main
const char* mainPointer = "a word";

my intention is to send a pointer to a function, that changes it(the pointer) but doesn't change the chars it is pointing to.


The following code (MS Visual C++ 2010) shows that it is perfectly possible and works. The output is: "World!"

#include "stdafx.h"
#include <iostream>
using namespace std;

void func(const char*& ptr) 
    ptr += 6;

int _tmain(int argc, _TCHAR* argv[])
    const char* Ptr = "Hello World!";
    cout << Ptr << endl;
    return 0;

Note that in contrast to Null Voids code, we do modify the pointer within func here.

Need Your Help

Using with a UICollectionViewFlowLayout that has UIDynamics

ios objective-c uicollectionview uicollectionviewlayout uikit-dynamics

Okay so basic overview. I have a UICollectionView that I needs to support adding and removing item through the performBatchUpdates: method. If I use a standard UICollectionViewFlowLayout, it works ...

Xpath - Filter if group-by parameter exists as child of another variable

xslt xpath foreach

I applied a for-each-group to a set of XML to sort. Now I need to add a filter to not process records where the group paramater exists in another variable. I'm not sure what the correct XPath stat...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.