473,385 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pointer and new

I am now reading a lot of C++ learning materials and encountered the following problems. Please help!

1. What is the difference between gcnew and new, and their uses?
2. What is the difference bettween pointer ^ and * ?
Mar 17 '07 #1
3 1383
DeMan
1,806 1GB
1)The first is quite easily answered by searching gcnew in google....
2) I've not come accross ^ used for pointers, the only use for ^ that I'm familiar with is to raise a number to the power of another number. As ^ and & are so close on the keyboard, though, I'll wax eloquent about & and * for a second:

You can think of * as a dereferencing operation and & as a referencing operation.....There are many tutorials available on the net, but I'll try a quick explanation....
when you use * you are saying "The value At", when you use & you are saying "The Address of". It satnds to reason, then that *(&a) is a.
The most common cause of confusion, is that people think of poth these operands as pointer indicators, rather than functions....
To declare a pointer, we say something like
Expand|Select|Wrap|Line Numbers
  1. int* a_ptr
If we substitute our earlier sentence for the asterisk, we are declaring "the value at" a_ptr to be of type int (so a_ptr is now a pointer). The hardest part I always found to understand, was when you later encounter
Expand|Select|Wrap|Line Numbers
  1. *a_ptr + x;
;
This can (when you are unfamiliar with pointers) appear to be saying "the pointer at a_ptr", but if we substitute in our sentence before it is really "the value at" a_ptr.

The & is the opposite operator. Obviously it wouldn't make sense to declare
Expand|Select|Wrap|Line Numbers
  1.  int &a;
bwecause you are saying "The Address of a" to be an integer (which it usually is, but we have no control over that). This operator is used when we want to use an address or pointer in a calculation....
If you have an integer a and you do something like (probably not a good idea unless you know what's going on)
Expand|Select|Wrap|Line Numbers
  1.  (&a)++;
you have set the pointer a to the location in memory after a (I'm pretty sure the compiler is clever, and knows how far to jump across the current element, no matter what it is)....

I know what I have written is a little confusing, so if there is anything specific you still don't understand, post again and I'll try to be a little clearer in my explanation.

One of the better books I have read on the topic is called(I think) simply.... "Understanding Pointers in C++" which you might like to look out for in library/bookshop...
Mar 18 '07 #2
arne
315 Expert 100+
I am now reading a lot of C++ learning materials and encountered the following problems. Please help!

1. What is the difference between gcnew and new, and their uses?
2. What is the difference bettween pointer ^ and * ?
Just like * denotes a pointer to an object returned by new, ^ denotes the handle of an object returned by gcnew. It's called a handle and is pointing to an object that is managed by garbage collection mechanisms.
Mar 18 '07 #3
DeMan
1,806 1GB
Learns something new every day.....
Mar 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Carsten Spieß | last post by:
Hello all, i have a problem with a template constructor I reduced my code to the following (compiled with gcc 2.7.2) to show my problem: // a base class class Base{}; // two derived...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
35
by: tuko | last post by:
Hello kind people. Can someone explain please the following code? /* Create Storage Space For The Texture */ AUX_RGBImageRec *TextureImage; /* Line 1*/ /* Set The Pointer To NULL...
16
by: junky_fellow | last post by:
According to Section A6.6 Pointers and Integers (k & R) " A pointer to one type may be converted to a pointer to another type. The resulting pointer may cause addressing exceptions if the...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
16
by: aegis | last post by:
Given the following: int a = 10; int *p; void *p1; unsigned char *p2; p = &a;
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
8
by: Martin Jørgensen | last post by:
Hi, "C primer plus" p.382: Suppose we have this declaration: int (*pa); int ar1; int ar2; int **p2;
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.