Accenture Placement: Sample Questions 8 - 9 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 8

Edit

Describe in Detail

Essay▾
  1. main()
  2. {
  3.     intc[ ]={2.8,3.4,4,6.7,5};
  4.     intj,⚹p=c,⚹q=c;
  5.     for(j=0;j<5;j++)
  6.     {
  7.         printf(" %d ",⚹c);
  8.         ++q;
  9.     }
  10.     for(j=0;j<5;j++)
  11.     {
  12.         printf(" %d ",⚹p);
  13.         ++p;
  14.     }
  15. }

Explanation

Table Shows the Program
int c [] = {2,3, 4,5, 6}Define integer array
Int jDeclare integer variable
⚹ p = c,

⚹ q = c

Pointer to c is pointer is assigned to p and q
  1. for(j=0;j <5;j++)
  2. {
  3.     printf(” %d “,⚹c);
  4.     ++q;
  5. }
In first for loop q increments and not c which points to beginning of array

So, print the value 2 5 times

  1. for(j=0;j <5;j++)
  2. {
  3.     printf(” %d “,⚹p);
  4.     ++p;
  5. }
Second loop increments the value of p and also prints what is pointed by p

So loop continues to run and prints 2 3 4 5 6

Question 9

Edit

Describe in Detail

Essay▾
  1. main()
  2. {
  3.     chars[]=“man
  4.     inti;
  5.     for(i=0;s[i];i++)
  6.     printf(“%c%c%c%cs[i],⚹(s+1),⚹(i+s),i[s]);
  7. }

Explanation

In a program

Table Shows the Program
char s [] = “man”It is define character array
int i;It is index number
for (i = 0; s [i] ; i ++)In for loop increment the array value
  • Here,
    • s [i] , ⚹ (s + i) , ⚹ (i + s) , i [s] are all different ways of expressing the same idea.
    • Mostly, arrary name is the base address, so here s is the base address.
    • Here, i is the define index number
    • So, indirectly ⚹ is same as s [i]
    • i [s] may be different, but in this case of c it is same as s [i] .
    • When first time call loop print m and increment the value of m and print the mmmm
    • When second time call loop print a and increment the value of a and print the aaaa
    • When third time call loop print n and increment the value of n and print the nnnn. s

Developed by: