Languages-C & C Plus Plus [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

C & C Plus Plus
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

 int c [] = {2,3, 4,5, 6} Define integer array Int j Declare integer variable ⚹ p = c,⚹ q = c Pointer to c is pointer is assigned to p and q for(j=0;j <5;j++){    printf(” %d “,⚹c);    ++q;} In first for loop q increments and not c which points to beginning of arraySo, print the value 2 5 times for(j=0;j <5;j++){    printf(” %d “,⚹p);    ++p;} Second loop increments the value of p and also prints what is pointed by pSo loop continues to run and prints 2 3 4 5 6

Question 9

C & C Plus Plus
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

 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: