On Feb 8, 2008 12:47 AM, nitika_puri85 <[EMAIL PROTECTED]> wrote:
> Hi Firiends,
>
> First of all i am not spammmmmmmm!!!

Debatable.

> I am nitika puri. working in MNC( micro controller). i am C/C++
> professional.
> From pasr 3 year i am into this field. I have filtered out some
> interview questions that will surely helps you to grab your dream job.
> Best of luck and work hard. . N reply in this post how was ur experince!!
>
> http://placementhelper.blogspot.com/2007/12/c-interview-questions_03.html

Let's pick one at random:

# 6. What will be the output of the following code?
#
# void main (){

main should return int. Not void, float or struct foo.

#     int i = 0 , a[3] ;
#     a[i] = i++;
#     printf ("%d",a[i]) ;

No prototype in existence for printf().

# }
#
# The  output  for the  above  code would  be  a garbage  value.

Assuming it compiles without warnings or errors, this is the only part
that's right.

# In the
# statement a[i] = i++; the value  of the variable i would get  assigned
# first to a[i]  i.e. a[0] and then the value of i would get  incremented
# by 1. Since a[i] i.e. a[1] has not been initialized, a[i] will have  a
# garbage value.

Right answer, wrong reason. The correct answer is:

The value i is modified once but read twice between sequence points,
rendering the expression, and hence the whole program, undefined. See
http://c-faq.com/expr/evalorder1.html


Another:

# 7. Why doesn't the following code give the desired result?
#
# int x = 3000, y = 2000 ;
#
# long int z = x * y ;

The premise behind the question, and answer, is compiler dependant,
since some compilers will quite legitimately return the desired
result.



Oh go one - one more:

# 8. Why doesn't the following statement work?
#
# char str[ ] = "Hello" ;
# strcat ( str, '!' ) ;

Because your compiler should at least complain, and at most not
compile the snippet. And variables starting with the characters 'str'
should not be created by a programmer - they are reserved for the
compiler writers.

# The  string  function  strcat(  )  concatenates  strings  and  not   a
# character. The basic  difference between a  string and a  character is
# that a string is a  collection of characters, represented by  an array
# of characters whereas a character  is a single character. To  make the
# above statement work writes the statement as shown below:
#
# strcat ( str, "!" ) ;

However the 'solution' is also incorrect since it suffers from a
buffer overflow. It appends two characters onto the end of str -
overwriting the nul that was there in the definition, and the
character after that which doesn't belong to str.



I think your page needs some work.



-- 
PJH

http://shabbleland.myminicity.com/ind

Reply via email to