Cognzant Technology Solutions Interview Question for Software Engineer / Developers






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

in case of ++*p++ u r dealing with two different storage.
1. *p
2. p
++*p is increasing the value pointed by p by one and p++ is increasing the value of p so there wont be any issue even though p++ is getting executed first.
But in case of ++i++ first i++ is getting executed which is returning a temporary object now u cant do ++(i++) because as soon as the statement get executed that temporary object will vanish so lvalue is required if u want to increase.
Though I feel that interpretation of ++i++ could be both (++i)++ or ++(i++) former is OK but latter will give u compilation error. Depends on compiler implementation which one it is choosing.

- Anonymous July 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Well, according to standard, postfix operator has higher priority than prefix, so last should be readed as ++(p++)

- Zerg July 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

in second last line,we can also write it as ++*(p++)...bcoz increment operator has more priority then * operator. ..so first post increment operator will b applied to p ,after this,pre increment operator will be applied to value at p.
in last second pre increment and post increment both operator have same priority and both are applied on same variable so it will cause a lvalue problem.

- priya garg April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

in second last line,we can also write it as ++*(p++)...bcoz increment operator has more priority then * operator. ..so first post increment operator will b applied to p ,after this,pre increment operator will be applied to value at p.
in last second pre increment and post increment both operator have same priority and both are applied on same variable so it will cause a lvalue problem.

- priya garg April 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

++*p++
the operators will be applied from right to left in this case so it will be equivalent to ++(*(p++))
++i++ is error because i++ will produce non-lvalue which cant be given to pre-increment operator .

- Ajax September 24, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

it will create a memory leak

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

yes it will create a memory leak. since the memory allocated for the pgm will be exceeded by the pointer.

- anand June 22, 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