Languages [Accenture Placement]: Sample Questions 1 - 2 of 9

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 1

Edit

Describe in Detail

Essay▾
  1. main()
  2. {
  3.     Floatme =1.1;
  4.     Doubleyou=1.1;
  5.     If (me==you)
  6.     Printf (“ILoveU”);
  7.     else
  8.     printf (“ IhateU”);
  9. }

Explanation

Table Shows the Program
float me = 1.1It defines float value
double you = 1.1It defines double value
if (me == you)Condition would be true if float and double values are equal.
  • For floating point numbers (float, double, long double) the values cannot be predicted exactly.
  • Float take 4 bytes
  • Double takes 8 bytes
  • Float value and double values are not same.
  • So, apply the else condition and print I hate U

Question 2

Edit

Describe in Detail

Essay▾
  1. main ()
  2. {
  3.     inti=-1, j=-1, k=0, l=2, m;
  4.     m=i++ &&j++ &&k++|l++;
  5.     printf(“%d%d%d%d%dI , j, k ,l ,m);
  6. }

Explanation

  • We, are know that Logical operators always give a result of 1 or 0.
  • And also the logical AND (&&) operator has higher priority over the logical OR (|) .
  • So, Expression i ++ &&j ++ && k ++ is executed first.

    So, result of this expression is 0 (-1 && -1 && 0 = 0)

  • So, the increment in i =-1

    i = 0

    Increment in j =-1

    j = 0

    Increment in k = 0

    k = 1

    Increment in l = 2

    l = 3

  • OR operator always gives 1 except for 0|0՚ combination-for which it gives 0.
    • The result of this expression is 0 (-1 && -1 && 0 = 0)
  • So, the value of m is 1
  • So, print 0 0 1 3 1

Developed by: