& symbol

Pages: 123... 5
Hello. Please explain to me the various different meanings and uses of &
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
Please xplain with example "& is also used for access and output of a memory address." Is it same as pass by reference?
closed account (1CfG1hU5)
what is pass by reference?
int func(int&); //prototype

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
closed account (1CfG1hU5)
int funct (int &); this function is set to pass a memory address
closed account (1CfG1hU5)
http://msdn.microsoft.com/en-us/library/17zwb64t.aspx
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.
closed account (1CfG1hU5)
here's another

http://www.learncpp.com/cpp-tutorial/38-bitwise-operators/
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
So & is for:

-Bitwaise and
-return mem add
-pass by ref which is access mem add?
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.
thanks
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
closed account (1CfG1hU5)
& helps access memory address of variable. char or integer.

& 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
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
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
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