473,326 Members | 2,081 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,326 software developers and data experts.

Difference between *variable and variable*

Does the placement of the * with respect to the variable name change its definition? e.g. is *variable a pointer or something else?

Also does variable** indicate a pointer to a pointer?
Mar 30 '15 #1
2 1271
weaknessforcats
9,208 Expert Mod 8TB
It works like this:

int x;

means that the variable x is an int.

Then:

int x, y;

means that x and y are ints.

Then:

int x, y, *z;

means that x and y and *z are ints.

The variable z is not an int but *z is an int.

z is called a pointer and normally contains the address of the int so that *z is the int at the address in z.

So:

int *z;

defines z as a pointer to an int.

In C the convention is to put the * by the z but in C++ the convention is to put the * after the t of int. It's all whitespace so you can put the * anywhere between the t of int and the z.

Therefore:

int x, **y;

means x is an int and **y is an int. Note that **y can be written as *(*y) making it clear that *y is a pointer to an int. That makes y a pointer to a pointer to an int.
Mar 30 '15 #2
donbock
2,426 Expert 2GB
Putting the * by int raises one risk:
int* x, y, z;
*x, y, and z are ints. The asterisk is associated with the variable, not the type.
Mar 31 '15 #3

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

Similar topics

10
by: Tanteauguri | last post by:
Hi List, is there in python a variable variable like in PHP ($$var)? What I want to do is something like that: pc= for i in pc: i = anyclass() a.shutdown()
11
by: pmatos | last post by:
Hi all, What's the difference between: int& i; and int i; ?
3
by: Sugapablo | last post by:
I would like to use variables in... for(q = 0; q < i; q++) { if(document.varArray1.varArray2.checked == TRUE) { alert("YES"); } else { alert("NO"); } }
9
by: mps | last post by:
Suppose..... arr = Array("only","a","test"); ArrayVar = "arr"; alert(ArrayVar); This the simplyfied version of my problem.. (alerting 'undefined' instead of 'only'...)
5
by: Ron | last post by:
I'm not really new to dotnet but am getting stumped by what I think is something easy. Any insights as to what i'm doing wrong? Thanks in advanced (see below) ------------------- This...
3
by: Ron | last post by:
I re posted beacause I copied and pasted my code incorrectly that it probably needed a re start with the correct code. I also striped out the Clone() stuff because that really had no bearing on...
11
by: mfglinux | last post by:
Hello to everybody I would like to know how to declare in python a "variable name" that it is in turn a variable In bash shell I would wrote sthg like: for x in `seq 1 3` do M$i=Material(x)...
1
by: rahatekarabhijeet | last post by:
I want to know the difference between, 1 . Declarations : $::varible and $varible 2 . Calling of functions : $::functions_output .= ::flatten_list($item); and $function_output =...
1
by: 55555 | last post by:
what is difference between variable type and object type??
2
Claus Mygind
by: Claus Mygind | last post by:
I have a method in a class that updates one of 7 variables/properties in the class. I would like to reduce the "switch" command to one line by using a variable variable, but I don't seem to be able...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.