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

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=“kishor”;
4.     printf(“n%u:%u”, a, &a);
5. }
6. Output:
7. 65516:65516

Question 42

C & C Plus Plus
Edit

Write in Short

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;
5. }
6. voidprint(intptr[size])
7. { coutptr;
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
 const int size = 5; Defines the constant integer variable size = 5 void print(int ⚹ptr){    cout ≪ ptr;} Defines the void print () function.Print () function defines the int ⚹ ptr arguments void print(int ptr[size]){    cout ≪ ptr;} Defines the void print () function.Print () function defines the int ptr [size] arguments void main(){    int a[size] ={1,2,3,4,5};    int ⚹b =new int(size);    print(a); print(b);} Main function defines the integer array a [size] = {1, 2,3, 4,5} ;Defines the integer pointer bBut 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: