# Thread: Am I doing these correctly?

1. ## Am I doing these correctly?

Ok, so I have no programming experience and I started using "Let Us C" by Yashavant Kanetkar to teach myself C a few days ago. Unfortunately, I don't have the solutions to the exercises in the book, so I was wondering if I could get a little help from y'all. Here's the exercise, with each statement followed by my answer:

Point out the errors, if any, in the following C statements:

1.
Code:
`int = 314.562 * 150;`
no error

2.
Code:
`name =  'Ajay';`
both quotes should point to the left (i can't show this on my computer, but one quote is pointing one way and the other is pointing the opposite way)

3.
Code:
`varchar = '3';`
both quotes should point to the left (i can't show this on my computer, but one quote is pointing one way and the other is pointing the opposite way)

4.
Code:
`3.14 * r * r * h = vol_of_cyl;`
variable should be on the left, constant on the right

5.
Code:
`k = (a * b)(c + (2.5a + b)(d + e);`
* must be used for multiplication

6.
Code:
`m_inst = rate of interest * amount in rs;`
variable names can't have spaces in them

7.
Code:
`si = principal * rateofinterest * numberofyears/100;`
no errors

8.
Code:
`area =  3.14 * r**2;`
should be re2, not r**2

9.
Code:
`volume = 3.14 * r^2 * h;`
should be re2, not r^2

10.
Code:
`k = ((a * b)+c)(2.5 * a + b);`
must use * for multiplication. can't have parenthesis within parenthesis

11.
Code:
`a=b=3=4;`
3 and 4 aren't the same? that's about all i can come up with.

12.
Code:
`count = count + 1;`
count isn't defined

13.
Code:
`date = '2 Mar 04';`
variables can't have spaces in them

Ok, as you can see, I'm pretty sorely in need of help. I really appreciate any assistance.

2. 1. int is a keyword
2. What you said
3. What you said
4. Technically it's not a constant...
5. What you said
6. What you said
7. What you said
8. What you said
9. Isn't technically incorrect (bitwise XOR), but given the context then it's wrong.
11. What you said
12. If it's defined then it's legal. Otherwise, most of the others would be wrong =)
13. Sure they can, this is valid but doesn't mean what you think it does. It's a multibyte character constant, all pasted together:
Code:
```#include <stdio.h>

int main(void)
{
unsigned int a = '1234';

printf("&#37;X & %u\n", a, a);

return 0;
}
[zac@neux ~]\$ gcc -Wall -pedantic -std=c89 ln.c -o ln
ln.c:5:12: warning: multi-character character constant
[zac@neux ~]\$ ./ln
31323334```
Notice that, '1' = 0x31, '2' = 0x32, '3' = 0x33 & '4' = 0x34

3. 9. What is bitwise XOR? I know what an exclusive or circuit is, but that's about it.
13. Ok, I think you lost me here completely. I'm completely new to all this. Why does '1' = 0x31, '2' = 0x32, '3' = 0x33 & '4' = 0x34? Where are the 30's coming from, and where is th multiplication coming from? I don't see any spaces in the constant there.

And by the way, thanks so much for your help. Taking the time to go through each one - very cool of you, and very helpful to me. Who says there's no manners left in the world? Hopefully I'll eventually know enough to pay it back!

4. > What is bitwise XOR?
exclusive-or at a bit level. It does the same thing as it does in a circuit. And as you know, a byte is made up of bits (usually 8 of them). It does an XOR on each bit of the byte (or bytes) -- it's an operator. See http://www.cprogramming.com/tutorial...operators.html for a tutorial. XOR is explained near the bottom of the page.