Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 41 - 43 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 41

C & C Plus Plus
Edit

Write in Short

Short Answer▾

Are the expressions arr and &arr same for an array of integers?

Explanation

Arr and &Arr both are same, which will return the address of first element of the array.

  1. voidmain()
  2. {
  3.     chararr[10]=“kishor”;
  4.     printf(“n%u:%u”, a, &a);
  5. }
  6. Output:
  7. 65516:65516

Question 42

C & C Plus Plus
Edit

Write in Short

Short Answer▾

Does mentioning the array name give the base address in all the contexts?

Explanation

  • Yes, mentioning the name of array provides the base address of the array.
  • Printing the name of array will print the base addres- while using printf () to print address uses % u and not % d as address are not integer, but unsigned integers

Question 43

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Find the output of the following program

  1. constintsize =5;
  2. voidprint(int ⚹ptr)
  3. {
  4.     coutptr[0];
  5. }
  6. voidprint(intptr[size])
  7. { coutptr[0];
  8. }
  9. voidmain()
  10. {
  11.     inta[size] ={1,2,3,4,5};
  12.     int ⚹b =newint(size);
  13.     print(a);
  14.     print(b);
  15. }

Explanation

  • In the program
Table Showing the Program
const int size = 5;
  • Defines the constant integer variable size = 5
  1. voidprint(int ⚹ptr)
  2. {
  3.     cout ≪ ptr[0];
  4. }
  • Defines the void print () function.
  • Print () function defines the int ⚹ ptr arguments
  1. voidprint(intptr[size])
  2. {
  3.     cout ≪ ptr[0];
  4. }
  • Defines the void print () function.
  • Print () function defines the int ptr [size] arguments
  1. voidmain()
  2. {
  3.     inta[size] ={1,2,3,4,5};
  4.     int ⚹b =newint(size);
  5.     print(a); print(b);
  6. }
  • Main function defines the integer array a [size] = {1, 2,3, 4,5} ;
  • Defines the integer pointer b
  • But arrays cannot be passed to functions, only pointers (for arrays, base addresses) can be passed.
  • So the arguments int ⚹ ptr and int ptr [size] have no difference as function arguments.
  • In other words, both the functions have the same signature and so cannot be overloaded.

Developed by: