i am new to c++

1. printf("%d", 10*5/10); what is this result?

2. printf("%d", 10+5-5); what is this result?

3. a=d++ +(b=a); a=4,b=4,d=4 a=?

4. c=a+ a++ - b--; a=4,b=4 c=?

5. c=a+ ++a - b--; a=4,b=5 c=?

6. if(a==0 && b==0) printf("1);
else
if(a==0 && b==0) printf("2");
else printf("3");

(if a=1 and b=0) what is the result?
(if a=0 and b=0) what is the result?
(if a=0 and b=1) what is the result?

please help me thanks regards...
Write a little program and you will be able to see all the results...
mmm i am just a student i cant write a programme:(
But that looks like homework. Are you getting homework on a subject you don't know?
mmm i am svetlana i am computer engineering student.i am at the first class we begin to c++ .that is not my homework but teacher gives that questions because she will ask them in visa exams.please help me for that.thanks...
I'd like to tell you that it depends on the environment,perhaps the result different form compiler to compiler.......
printf() is the C function for writing to the standard output (normally, the console, but not always). It takes a C string that tells it what to write and what other parameters, if any, it will receive.
Example:
printf("2+2=%d\n",2+2);
This will print "2+2=4" and will advance the cursor to the next line.
'\n' is what is known as an escape character. It's used to represent special characters in string literals. The most commonly used are:
\n - New line
\t - Horizontal tab
\\ - Backslash
\0 - Null character
Escape characters are not particular to printf(). They are part of the C syntax.
"%d" is a special sequence that gives printf() information about the parameters that are being passed to it. In this case, it's telling it that the parameter in question is a signed (i.e. can be positive or negative) number. There's quite a few of these:
%d - Signed integer
%u - Unsigned integer
%f - Floating point number
%c - Character
%s - C string
%x - Unsigned integer expressed in hexadecimal with lower case characters
%X - Same as above but with uppper case characters
I can't explain all the things that can be done with printf(). If you're interested, you can check the reference: http://www.cplusplus.com/reference/clibrary/cstdio/printf.html

As for operators, it's easier to explain with examples than in words:
1
2
3
4
5
6
7
8
9
10
11
12
int a=5;
int b=++a;
/*
a now equals 6.
b also equals 6.
*/
a=5;
b=a++;
/*
a now equals 6.
b now equals 5.
*/

The prefix operator (++a) first increments the variable, and then assigns the incremented value, while the postfix operator (a++) assigns the unincremented value first, and then increments the variable.

It's possible to write books on boolean operators, so I'll just give you a very brief summary:

T is true and F is false
a b a && b
F F F
F T F
T F F
T T T

a b a || b
F F F
F T T
T F T
T T T


Relational operators compare to values:
a==b returns true if a equals b
a!=b returns true if a does not equals b
a<b returns true if a is lower than b
a>=b returns true if a is greater than or equal to b
a<b returns true if a is greater than b
a>=b returns true if a is lower than or equal to b
mmm i really dont understand anything sorry.i am really very enw to c++. can u give just answers.and i dont know how to use a complier.please help...
No, we are not a homework service.

You are a computer engineering student. You need to learn this stuff. Having us just give you answers is a disservice to you, since you will learn nothing, and to us as professional programmers since we would only end up doing your work too should you be hired at one of our companies.

Take a look at how to install MSVC++ and write simplest programs:

http://simpleprogrammingtutorials.com/tools/first-string-cpp.php

Hope it helps.
If you dont even know what a compiler is and how to use him, i would start with dev-cpp, because its easier to work with then Visual Studios:
http://www.bloodshed.net/devcpp.html
If you dont know how to use it, google for a tutorial or take a look at the one at this site (or maybe even read your books?).

Btw, if you are learning c++, I dont understand you're using (c-style) printf().
4 and 5 look like trick questions...
I think 4 and 5 have answers because the post- and pre-increment/decrements occur only on the last use of the variables.

If the expressions were

c = a++ - a - b--; // post-increment on first use of a instead of last use

then I think the answer is undefined because the compiler is free to post-increment a either immediately after reading the first addend or any time thereafter, which would mean that the expression could have the value -1 - b (if a were post-incremented after loading the first addend but before evaluating the second occurrence of a) or -b (if a were post-incremented after evaluating the entire expression).

Am I the only one who is unsure about those notes after 4 and 5? Are they supposed to be a and b's previous or current values?
I assumed they were the values assigned to the variables prior to executing the statement.
I think a/b are the values before (but like you say, it could be either way) and they want you to fill in c.
I suppose in Soviet Russia, initializations go after operations. And then, they go after YOU No, that's just too stupid.

Is this off-topic enough? Yes.
My work here is done.
Last edited on
Topic archived. No new replies allowed.