Intel Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

If int i is not initialized then both expression ( assignment to a = (++i) ; and a = (i++) ) are wrong . Compiler Will produce an error related to initialization of integer i.

- shravan40 September 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

There are a lot of correct answers below about pre-increment and post-increment.

If this were the actual interview question, I would clarify with the interviewer if i or a have been initialized. If the above snippet is all that is provided, then the compiler will complain on both about un-initialized variables, and be unable to perform operations.

On the other side, if the variables are initialized, you will get a different kind of error for both. The pre/post increment causes that side of the expression to be a value not a variable. The compiler cannot assign the value of a to another value. It will have to assign it to a variable.

- masterjaso September 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
4
of 4 vote

i++ increments the variable but returns its value before the increment.
++i increments the variable and returns a reference to the variable.

the = operator needs a L-value on the left side to be able to assign the value of a to i. the first statement does not return an L-value, while the second statement does (return variable i).

- Miguel Oliveira September 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sup i=10, a=3;
->: ++i = a
-> : (i=i+1)=a //highest priority operator ++ other than = ,because first execute the left side statement
-> : i=11=a //here variable 'a' require left value.so,the compiler produced error "L Value required"
*This is same as post and pre increment

- Anonymous September 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sup i=10, a=3;
->: ++i = a
-> : (i=i+1)=a //highest priority operator ++ other than = ,because first execute the left side statement
-> : i=11=a //here variable 'a' require left value.so,the compiler produced error "L Value required"
*This is same as post and pre increment

- karthi September 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

thanks..

- Rahul September 11, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

(++i) = a; // correct, the value of i increases and i is used as a variable.
(i++) = a; // incorrect, it tries to assign values to (i++), which is an operation, not a variable.

- tae September 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

(++i) = a is correct, and (i++) = a is wrong.

If you use C++ and operator overload, you will know why: (++i) returns a l-value (like variable), while (i++) returns r-value, which cannot be assigned a value.

- Anonymous September 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

(++i)=a is correct
i++=a is incorrect
as ++i can be used as L-value
any pre-increement or pre decreement can be used as L-value
but post-increement cannot be used!

- mahima September 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

plz give me same type of examples...

- Rahul September 11, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

None of them are correct!
Rule :
When executing "x=y", 'x' should be assignable(for example, address where you store)

reason :
(++i) increments value of i and gives you after increment "value of 'i'"
(i++) gives you "value of i" and then increments 'i'.
So in the given problem, (++i) or (i++) always gives you "value" either before increment or after increment, to which you cannot "asssign some other value directly.

gcc gave me "error: lvalue required as left operand of assignment" for both

- TG September 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

(++i) = x;
compiles fine with g++ 4.2.1 on mac os

- Miguel Oliveira September 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

If you read the C or C++ standard, both would be wrong.

A compiler is more likely to accept ++i, but you should not code this way as it is not strictly allowed in the standards.

- bigphatkdawg September 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Actually, ยง5.3.2.1 states "The operand of prefix ++ is modified by adding 1, or set to true if it is bool (this use is deprecated). The
operand shall be a modifiable lvalue."

postfix ++ is a prvalue though, so it can not be modified.

- elau89 March 02, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

main.c:8:8: error: lvalue required as left operand of assignment
++i = a;
^
main.c:9:8: error: lvalue required as left operand of assignment
i++ = a;
^

- kate November 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Both are wrong. We need an lvalue.

- Anonymous August 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think both of them are wrong.because left hand side i cant use the increment operator

- Anonymous June 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

both are correct syntax wise(if they are initialized). post increment require another location to hold incremented value when compared to pre increment. So I will prefer pre-increment

- kiran July 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

What exactly are you looking for, that is the question?

- AnkitSablok19091989 September 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

both the lines are correct provide some initial value for i... here i++ is a post increment operator where value is assigned first and then incremented.whereas ++i is a pre increment operator where value is incremented and then assigned.

- ayushsethi22031992 September 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi, I've corrected the questions. The previous one has problem and is not the REAL questions

- James Liu September 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Am i wrong?
I have tried this code with MinGW,
++i=a ----> right
i++=a ----> compiler error

no matter i and a instantiated or not!

- traveller September 10, 2013 | Flag Reply


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