Dover Organization Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

1. x=13,y=21;
3. **p points the value at the address which is stored at address p and &(*p) points address p

- Neetesh Bhardwaj April 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Answers:
1. x=14,y=21
3.**P points to the location that *p points...
and &(*p) gives the address of value that p points...

- vindu525 April 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. x=13, y=21;

- Heena April 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x=13, y=21

- tiku April 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x=11,
y=20

- Anonymous April 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

int x, y;
x = 5; y = 6;
x = y++ + x++; // x is 12 (5+6 = 11 and then x is incremented to 12 and y to 7)
// y = 7 now and x =12
y = ++y + ++x;// 8 + 13
// x = 12, y = 20

- Anonymous June 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

int x, y;
x = 5; y = 6;
x = y++ + x++; // x is 12 (5+6 = 11 and then x is incremented to 12 and y to 7)
// y = 7 now and x =12
y = ++y + ++x;// 8 + 13
// x = 13, y = 21

- Anonymous June 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

X= 12,
Y = 20

int x, y;
x = 5; y = 6;
x = y++ + x++; // x is 11 (5+6)
// y is 7 now
y = ++y + ++x;// 8 + 12
// x = 12, y = 20

- Rohit April 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

warning: operation on ‘x’ may be undefined
warning: operation on ‘y’ may be undefined

Why do they ask such questions.

- anon.coder April 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I agree that it's very dumb of companies to ask stuff like this. No sane person programs using these sorts of constructs anyway, so if you don't know this kind of stuff, to me that would say good things about you.

- Anonymous April 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Its not a warning. Its compile time error in latest version compilers(C-99 onwards).

- Aashish June 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I was asked a similar question during a phone interview.

According to the C standard, you are not supposed to modify a value more than one time between sequence points:

"Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored."

Each of the assignment statements above falls within a single set of sequence point boundaries. (There is a sequence point at the beginning of the assignment statement and one at the end of the assignment statement, and none in between.) So, according to the standard, this is not a legal C or C++ program.

At least with gcc v4.6.1, the following code generates two different numbers depending on whether the optimizer is enabled:

int x, zero;
    zero = 0;
    x = 5;
    printf("(zero + ++x) * (zero + --x):  %d\n", (zero + ++x) * (zero + --x));

- gregfjohnson April 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

13,21

- kuldeep June 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The output of first program is undefined. There is no sequence defined in the statement:
x = y++ + x++;
y = ++y + ++x;

In the older version compilers, the output is 13.......21, but the newer version compilers(c-99 onwards) define the behavior as undefined.You will get the error.
See here: ideone.com/mEqiP

If the value of the same variable is changed more than once, then it is called as UB(undefined behavior).
For more details, search sequence point on wiki.

- Aashish June 27, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More