MikeyBoy (2435), int funct (int &); this function is set to pass a memory address
No it isn't - it passes a reference. That's not a memory address.
******************************************************
could have said, (int &) is a pointer and a parameter (which has a memory address) ready to receive a pointer to a variable's address, x for example, passed as &x, possibly passed as (x) if the pointer definition can manage just the (x), but from what i've seen, passed as (&x) by the function called from main or other func. :) so, essentially (int &) is an address pointer to an address pointer for a variable declaration whether assigned or not, or assigned by the compiler without the user's use of an '=' operator.
http://www.cplusplus.com/doc/tutorial/pointers/
no questions please, couldn't possibly bear that. :)
could have said, (int &) is a pointer and a parameter (which has a memory address) ready to receive a pointer to a variable's address, x for example,
I'm beginning to believe you're a troll. None of that paragraph is true. I would advise the OP and anyone else reading this for information to just ignore posts by jt1.
some of that was mockery. is called, being tired of stupid ridiculous posts in counter.
int funct (int &): int & is a pointer paramater for an address that can be passed to the function.
the function's memory address points to a variable memory address passed
such as &x. x may be an integer declaration such as "int x = 2;".
some of that was mockery. is called, being tired of stupid ridiculous posts in counter.
int funct (int &): int & is a pointer paramater for an address that can be passed to the function.
the function's memory address points to a variable memory address passed
such as &x. x may be an integer declaration such as "int x = 2;".
& helps access memory address of variable. char or integer.
MikeyBoy (2435)
& helps access memory address of variable. char or integer.
Why are you specifically limiting this to char and integer variables? & before the name of an object or variable signifies the address of (or a pointer to) that object, regardless what type it is.
Last edited on Oct 14, 2014 at 4:33pm Report
Oct 14, 2014 at 4:58pm
jt1 (136)
i did not declare a limit. helps access char or integer. & may have other uses. happy
MikeyBoy is upset. look into reference section(s) to see what other uses "&" may have.
Last edited on Oct 14, 2014 at 4:58pm EditReport
Oct 14, 2014 at 5:00pm
jt1 (136)
there are a couple program examples above. how "&" is used for bits and hex memory address output.
responding:
who are you replying to zhuge?
int, char, string. typical data types. i did not mention float data type "0.00"
these pages for reading:
http://www.cplusplus.com/doc/tutorial/variables/
http://www.cprogramming.com/tutorial/c/lesson1.html
http://www.cprogramming.com/tutorial/lesson1.html
Last edited on Oct 14, 2014 at 6:20pm EditReport
Oct 14, 2014 at 5:03pm
Zhuge (4104)
You should be more clear with what you are writing; unclear information can be highly detrimental when you are trying to answer someone's question. All your posts in this topic seem very hastily written and not well thought out, with only the most basic understanding of what you are saying evident. If English isn't your native language, I would politely request that you spend more time editing your work before posting it to improve readability and prevent these misunderstandings from occurring.
========================================
what's highly detrimental is your miscommunicated statement of a highly detrimental nature
that doesn't exist here except maybe about yourself. i don't care for haste bs talk. i don't need you as a critic in the manner you have been speaking, zhuge. I do not like people posting
stupidly about me and had better end.
some of that was mockery. is called, being tired of stupid ridiculous posts in counter.
int funct (int &): int & is a pointer paramater for an address that can be passed to the function.
the function's memory address points to a variable memory address passed
such as &x. x may be an integer declaration such as "int x = 2;".
Again, entirely incorrect.
1. int & is an address pointer
2. if &x were passed, is a pointer to x's address
3. int & function parameter has to be kept track of by language, not lost, so
int & must point to passed &x address pointer.
4. some of the context of the message "was" mockery. wrong again that the text was not.
5. type passed to function has to be type integer according to the (int &) in parentheses.
entirely incorrect?
you need some sleep maybe
start explaing what is entirely wrong, and you better be accurate.
1. int & is an address pointer
2. if &x were passed, is a pointer to x's address
3. int & function parameter has to be kept track of by language, not lost, so
int & must point to passed &x address pointer.
4. some of the context of the message "was" mockery. wrong again that the text was not.
5. type passed to function has to be type integer according to the (int &) in parentheses.
entirely incorrect?
Yes. Entirely incorrect.
1: int& has the type "reference to int"
2: If &x were passed, the compiler would barf on it, because binding a temporary to a non-const reference is not legal (assuming the address is convertible to int without explicit casting.) If you happen to be using some version of VC++, there is an extension enabled by default that allows it, but even in that case what you describe happening is not correct.
3: Since 2 is illegal, 3 is nonsense.
4: It wouldn't seem to be since you repeated it in the last post. But perhaps the only person you're mocking is yourself.
5: We don't pass types to functions; we pass arguments. The argument to the function must be of a type that can be bound to a "reference to int." We could not, for instance, call the function with a literal (i.e. funct(32)) even though 32 is an int, because the parameter type is not int. It is "reference to int."
int is the type, & is the pointer operator. i have visual studio. not with me at this time.
what would be passed to the (int &) in parentheses?
I wasn't suggesting pass 32 directly as a decimal value to the function.
i would believe funct( &x );
maybe funct( x ); // i am more familiar with a dos compiler. maybe this won't work because
// would be like doing as you said funct(32).
did this example earlier 1st page:
1 2 3 4 5 6 7 8 9 10 11
#include <stdio.h>
int main() // removed void in parentheses
{
unsignedint a = 1, b = 2, c = 3;
printf("the memory address of a is 0x%x\n", &a);
printf("the memory address of b is 0x%x\n", &b);
printf("the memory address of c is 0x%x\n", &c);
return 0;
}
cpp.sh web site will show yellow triangles. the memory addresses print to screen okay.
the site is erroring when complaining about an "unsigned integer*" or maybe a compatability
issue.
only partially correct.
& is context-dependend token
If you see & as binary operator (between two values) it is bitwise and
If you see & as unary operator (before variable) it is address-of operator
if you see & as part of type (after typename) it is reference.
1 2 3 4 5 6 7 8 9
void foo(int& x)
{}
int main()
{
int a;
foo(a); //Correct, reference, not pointer is passed
foo(&a); //Trying to pass pointer in function expecting a reference, error
}
void foo(int& x)
{
x = 5; //Changing passed argument
}
int main()
{
int a;
foo(a); //Passing a reference
//a now is 5
}
References are not pointers. They are different. Reference have some restrictions placed on them if you were compare them to pointers, but give some new possibilities, you cannot achieve with pointers.
first I thought funct( &x ), but also thought maybe funct ( x ). cire typed text about
not doing funct(32) for example, so then I was reasoning out the funct( x ) because
that would be like doing funct(32).
thanks for your example. good to know pass the var only.
i have visual studio 2013 on another computer. am not fully learned regarding
changes.
does format matter if, (int &), or does have to be (int& x)? maybe a previous post did not
include enough information.
Spaces between type/pointer or reference symbol/name are not important:
1 2 3 4 5 6 7 8 9
int& x = /*...*/;
int & x = /*...*/;
int &x = /*...*/;
// ↑ x is a reference to int. No difference between declarations
int* y = /*...*/;
int * y = /*...*/;
int *y = /*...*/;
// ↑ y is a pointer to int. No difference between declarations
didn't know that & or * were equivalent for same purpose.
They are not equivalent. At all. In any context.
When applied to type & is reference, * is a pointer. When applied to variable, & is an address-of, * is dereference.