& symbol

Pages: 123... 5
Oct 14, 2014 at 4:51pm
Hello. Please explain to me the various different meanings and uses of &
Oct 14, 2014 at 5:16pm
closed account (1CfG1hU5)
& can bit change. & is also used for access and output of a memory address.

using "&&" is for logical statements.

1
2
3
4
5
6
7
8
if (r == 8 && r2 ==9)
  // then do statement(s) here.  if more than one statement below if, use braces

if (r == 8 && r2 == 9)
  {
     // 1st statement
     // 2nd statement ...
  }


Bitwise AND

The bitwise AND operator is a single ampersand: &. A handy mnemonic is
that the small version of the boolean AND, &&, works on smaller pieces (bits
instead of bytes, chars, integers, etc). In essence, a binary AND simply takes
the logical AND of the bits in each position of a number in binary form.

http://www.cprogramming.com/tutorial/bitwise_operators.html
Last edited on Oct 14, 2014 at 5:33pm
Oct 14, 2014 at 5:21pm
Please xplain with example "& is also used for access and output of a memory address." Is it same as pass by reference?
Oct 14, 2014 at 5:26pm
closed account (1CfG1hU5)
what is pass by reference?
Oct 14, 2014 at 5:26pm
int func(int&); //prototype

Oct 14, 2014 at 5:27pm
closed account (1CfG1hU5)
run this with with cog icon to right

1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>

int main(void)
 {
   printf("0 & 0 is %d\n", 0 & 0);
   printf("0 & 1 is %d\n", 0 & 1);
   printf("1 & 1 is %d\n", 1 & 1);
   printf("1 & 2 is %d\n", 1 & 2);
   printf("15 & 127 is %d\n", 15 & 127);
   return 0;
 }
Last edited on Oct 14, 2014 at 5:29pm
Oct 14, 2014 at 5:29pm
closed account (1CfG1hU5)
int funct (int &); this function is set to pass a memory address
Oct 14, 2014 at 5:30pm
closed account (1CfG1hU5)
http://msdn.microsoft.com/en-us/library/17zwb64t.aspx
Oct 14, 2014 at 5:33pm
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.
Oct 14, 2014 at 5:34pm
closed account (1CfG1hU5)
here's another

http://www.learncpp.com/cpp-tutorial/38-bitwise-operators/
Oct 14, 2014 at 5:42pm
closed account (1CfG1hU5)
1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>

int main(void)
 {
   unsigned int 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 complains about a pointer is what looks like, the memory address display ok.
Last edited on Oct 14, 2014 at 5:56pm
Oct 14, 2014 at 5:47pm
So & is for:

-Bitwaise and
-return mem add
-pass by ref which is access mem add?
Oct 14, 2014 at 5:56pm
closed account (1CfG1hU5)
&, changes bits
&, reads memory address
&, displays memory address
&, can pass memory address to function

read website about & bit changes. go to a reference page. get accurate information.
Oct 14, 2014 at 6:01pm
thanks
Oct 14, 2014 at 6:34pm
As MikeyBoy pointed out, & is also used for references, which are NOT addresses.

1
2
3
4
5
6
7
void functionWithPointer(int* a);
void functionWithReference(int& a);
...
int x;
functionWithPointer(&x);
functionWithReference(x);
...


Line 2 shows a function that takes a reference (identified by the '&') as an argument.
Line 5 shows the '&' taking the address of x being passed to a function taking a pointer as an argument.

Edit: Also, the '&' does not "display" anything, just provides access to the address of a variable.
Last edited on Oct 14, 2014 at 6:37pm
Oct 14, 2014 at 9:45pm
closed account (1CfG1hU5)
& helps access memory address of variable. char or integer.

Oct 14, 2014 at 11:32pm
& 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 11:33pm
Oct 14, 2014 at 11:58pm
closed account (1CfG1hU5)
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 11:58pm
Oct 15, 2014 at 12:00am
closed account (1CfG1hU5)
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 15, 2014 at 1:20am
Oct 15, 2014 at 12:03am
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.
Pages: 123... 5